WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm managing a movie related site.. I'm using yoast's simple taxonomies plugin to classify my content with Artists, Genre (action, horror, comedy, drama etc..), Director, Writer etc...

On a specific page (template), I want to pull last 5 posts with only their titles from custom taxonomies.. how can I pull last 5 titles from Action, Comedy or Horror taxonomies as list?

I will try to get an output like http://tutsplus.com/


share|improve this question
genre is the taxonomy and Action, Comedy or Horror are terms in that taxonomy? – Bainternet Jun 5 '11 at 16:49
up vote 1 down vote accepted

create additional loops in your template, selecting the taxonomy and term you'd like to limit display to for each. for instance, this will pull the last 5 posts from taxonomy "genre", term "action":


$args = array( 'taxonomy'=>'genre','term'=>'action','posts_per_page'=>5 );
$action_films = new WP_Query( $args );

while( $action_films->have_posts() ) : $action_films->the_post();
    echo '<li>';
    echo '</li>';

share|improve this answer
Im still kind of new to the whole php stuff but why not use a for each statement? – xLRDxREVENGEx Jun 5 '11 at 16:51
@xLRDxREVENGEx - I guess you could use a foreach, though you'd have to do foreach $results->posts as $item since the results are an object containing an array of posts, not just a flat array. you'd still have to call $results->the_post() to set up the data properly for all the template functions. I sometimes use a foreach if I'm accessing data directly from the object, but otherwise while is simpler, and what WordPress uses in their code and docs. – Milo Jun 5 '11 at 17:16
great!.. that was exactly what I wanted.. just forgot to mention permalink.. but Bainternet provided related code.. thanks :) – teja Jun 5 '11 at 17:58

alternative approach :

$genres = array('action','drama','horror','comedy');
foreach ($genres as $genre){
    $query = new WP_Query( array( 'posts_per_page' => 5, 'genre' => $genre ) );
    echo '<div class="genre-list"><ul>';
    while ($query->have_posts()){
        echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
    echo '</ul></div>';
share|improve this answer
thanks for this approach also.. :) – teja Jun 5 '11 at 17:58

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.