I built 2 custom posts (firemen and mario) for my template, and that i designed for all of them 2 taxonomy (type-mario and also the term game, type-firemen and also the term game) right now I personally use query_posts() for showing title of both posts related to their term however i d'like to make use of get_posts() rather.

<?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(); ?>


<?php query_posts( array( 'type-firemen' => 'games', 'showposts' => 10 ) ); ?>
<p> Firemen 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(); ?>

It work nicely but I am confident it's easier to use get_posts() to exhibit individuals 2 title posts, but I'm not sure how to achieve that.

PS: Keep in mind that you will find 2 customs posts and never classical posts, the reason for I needed to develop a taxonomy for every of my posts with similar term ...

Interesting advices.

This is a solution:

<?php $posts = new 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(); ?>

If you have seen the documentation on [cde] it truely does work much like get_posts().

The main difference between your two is the fact that with query_posts() it'll modify globals to ensure that you will find the utilisation of the "the_..." global functions.

With query_posts() it'll return a range of publish objects which you'll loop through without having affected the present Loop if any. Furthermore you are able to loop through multiple publish sets.

Note: within the WordPress example, the get_posts() function can be used, which adds the publish object like a global to ensure that you're then able to utilize the "the_..." global functions (carrying this out however will modify the Loop).

Note: setup_postdata($post) should go ahead and take same parameters as get_posts().