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.
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
Reset to default 1Untested 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.