Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I currently use query_posts to show these custom posts but I'm pretty sure that I should uses get_posts() to write it correctly.

<?php query_posts( array( 'type-mario' => 'games', 'showposts' => 10 ) ); ?>
<p>Mario games</p>
<?php while ( have_posts() ) : the_post(); ?>
 <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
 <h2><?php the_title(); ?></h2>
 </div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>

Thanks for your advice.

share|improve this question
add comment

2 Answers 2

up vote 10 down vote accepted

Hi Elium2009:

Using your code, I think this is what you were looking for? (note that WP_Query() is just the more direct version of get_posts()):

<?php $posts = WP_Query(array( 
   'taxonomy' => 'type-mario'
   'term' => 'games',
   'posts_per_page' => 10 
)); ?>
<p>Mario games</p>
<?php while ( $posts->have_posts() ) : $posts->the_post(); ?>
  <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <h2><?php the_title(); ?></h2>
  </div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>

Hope this helps?

share|improve this answer
    
THX !!!!!!!!!!!!!!!!! Exactly what I needed :) –  Elium2009 Nov 12 '10 at 1:24
    
@Elium2009 - Welcome. :) –  MikeSchinkel Nov 12 '10 at 8:25
add comment

You can use either really, but if you want to use get_posts this is how it's done:

<?php query_posts('post_type=games&posts_per_page=10'); ?>
<?php if(have_posts()) : while (have_posts() ) : the_post(); ?>
...
<?php endwhile; endif; ?>
share|improve this answer
    
Thanks, but I'd like to get it from my custom taxonomy associate to my custom-post, here type-mario is my taxonomy associate ton a custom-post and games his term. How would you do that ? –  Elium2009 Nov 11 '10 at 22:34
1  
Did you try to add the tax and term in the above code?<?php query_posts('post_type=games&posts_per_page=10&taxonomy=type_mario&term=games'); ?> <?php if(have_posts()) : while (have_posts() ) : the_post(); ?> ... <?php endwhile; endif; ?> –  Drai Apr 5 '12 at 4:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.