Search code examples
phpwordpressloopstaxonomycustom-post-type

Display all posts from latest taxonomy in wordpress


I am creating a newspaper website that will have Volumes and Issues. Volumes increment yearly, issues increment weekly. I have created a custom post type of article with a taxonomy of issue.

Currently the code below will get the most recent post from the article with the most recent issue taxonomy. I want it to get all of the posts from the most recent issue. I figured out I can get the next post by changing $issue[0]->slug to $issue[1]->slug. I realize I just need a loop but I cant quite figure it out.

Your help is appreciated.

<?php
$issue = get_terms('issue','orderby=none&order=DESC');
$latest_edition = $issue[0]->slug;

query_posts('&post_type=article&gdsr_sort=thumbs&gdsr_order=desc&issue='. $latest_edition) . '&showposts=99'; ?>

Solution

  • You're not looping through your posts. You need to do something like:

    // Returns an array issues
    $issue = get_terms('issue','orderby=none&order=DESC');
    
    // You want the most recent issue
    // i.e. that which has an array key of 0
    $latest_edition = $issue[0]->slug;
    
    // Return all the posts for this issue
    query_posts('&post_type=article&gdsr_sort=thumbs&gdsr_order=desc&issue='. $latest_edition) . '&showposts=99';
    
    // Loop through each post
    while ( have_posts() ) : the_post();
       // Echo out whatever you want
       echo '<li>';
       the_title();
       echo '</li>';
    endwhile;