最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

hooks - Reverse order of posts in a certain taxonomy archive?

programmeradmin2浏览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.

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.

Share Improve this question edited May 15, 2020 at 18:03 OsakaWebbie asked May 15, 2020 at 17:54 OsakaWebbieOsakaWebbie 1136 bronze badges
Add a comment  | 

1 Answer 1

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

发布评论

评论列表(0)

  1. 暂无评论