Get the latest taxonomy/category?

I’m designing a custom magazine theme, where categories are used for different sections, and I created a custom “edition” taxonomy.

The editor will create a new term in that taxonomy for each new edition published, i.e. the number of the issue.

Read More

How can I query the latest “edition”, so I can combine it with each category and then publish only the posts that belong to the newest edition?

Something along the lines on:
?edition=34&cat=studies

Related posts

Leave a Reply

2 comments

  1. The latest edition should always be the term in that taxonomy with the highest term_id, right? Query get_terms and find the latest edition, then use that term to build the rest of your query…

    $edition = get_terms('edition','orderby=none&order=DESC&number=1');
    $latest_edition = $edition[0]->slug;
    

    Then you can either modify the current query, if that’s what you want to do:

    global $wp_query;
    $wp_query->set('edition',$latest_edition);
    

    Or use it to build new queries:

    $studiesposts = get_posts('category_name=Studies&edition='.$latest_edition);
    

    If you have your permalink structure set up, it should also work to build urls for new links, like this:

    http://yourdomain.com/edition/34/category/studies