0

I have a custom post type message which has a custom taxonomy called series. Is there a way to reverse the date order of the posts in just that archive (oldest first)? I want to continue to show newest first in the basic all-messages archive as well as archives based on other taxonomies.

There are plenty of examples of how to do it for all archives, like this:

add_action('pre_get_posts', 'change_post_order');
function change_post_order($query){
    $query->set('order','ASC');
    $query->set('orderby','date');
}

But I don't know how to limit it to archives of just the series taxonomy.

1 Answer 1

1

Untested but can you do:

add_action('pre_get_posts', 'change_post_order');
function change_post_order($query){
    if($query->is_tax('series')) {
        $query->set('order','ASC');
        $query->set('orderby','date');
    }
}

Based of this and this.

4
  • That has no effect, and I'm not surprised. It's not a category term called "series", but a whole custom taxonomy (not categories or tags) called "series" with its own terms. May 15, 2020 at 18:41
  • 1
    @OsakaWebbie Sorry if I'm still not understanding but in that case would you not use is_tax instead?
    – Bob
    May 15, 2020 at 18:54
  • 1
    Yes, is_tax('series') is exactly what I needed! Edit your answer and I'll accept it as the official answer. May 16, 2020 at 10:19
  • There you go, glad it helped :)
    – Bob
    May 16, 2020 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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