문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 wordpress.stackexchange
scroll top