Different order for posts in different categories
-
I have posts (default post type) in various categories, generally as “news” and “events”. I would like to show the events in the category archive in ascending order (oldest first) while news would be descending (newest first). How would modify the main loop to achieve that?
I’ve tried the following code in functions.php but apparently it isn’t working as intended:
function reverse_order($query) { if(!is_admin() && $query->is_main_query() && $query->is_category(6) || $query->cat_is_ancestor_of( 6, get_query_var( 'cat' ) )) { $query->set('order','ASC'); } } add_action('pre_get_posts', 'reverse_order');
FYI: category ID 6 is the events category.
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Different order for posts in different categories’ is closed to new replies.