0

I have a custom taxonomy called Issues (like magazine issues) with categories named after the title of each issue. I created a page called "Current Issue" and added a link to it in the main navigation of the site.

This is the loop I have in the page template now:

$categories = get_terms('issue', 'orderby=count&order=asc');
 foreach( $categories as $category ): 
 ?>
 <h3><?php echo $category->name; ?></h3>
 <?php
 $posts = get_posts(array(
 'post_type' => 'issue_posts',
 'taxonomy' => $category->taxonomy,
 'term' => $category->slug,
 'nopaging' => true,
 ));
 foreach($posts as $post): 
 setup_postdata($post); 

It does order the categories and posts appropriately, but this pulls in all the posts for all the categories. I need the link to show only the posts from the most recent category.

Thanks in advance for any help

0

Terms are assigned a unique ID when added, and the ID will always increment, so the most recently added term will be the one with the highest ID.

With this in mind, if you fetch a single term ordered by ID in descending order, you should get the most recently added term:

$args = array(
    'number' => 1,
    'orderby' => 'ID',
    'order' => 'DESC'
);

$recent_issue = get_terms( 'issue', $args );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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