Forked from mahodder/Reverse WordPress Archive Category Order
Created
October 19, 2019 14:12
-
-
Save itsjusteileen/eed028876e87d1dc2b82bdff157cbf8c to your computer and use it in GitHub Desktop.
Reverse WordPress post order on archive pages for specific categories only - add to functions.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'pre_get_posts', 'custom_reverse_post_order' ); | |
function custom_reverse_post_order( $query ) { | |
if ( is_admin() ) | |
return; | |
if ( $query->is_main_query() && is_archive() && ! is_post_type_archive() && ($query->query_vars['category_name'] == 'category-name' || $query->query_vars['category_name'] == 'category-name') ) { | |
$query->set( 'orderby', 'date' ); | |
$query->set( 'order', 'ASC' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment