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 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

share|improve this question
add comment

1 Answer

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 );
share|improve this answer
add comment

Your Answer

 
discard

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.