Created
January 24, 2014 03:47
-
-
Save mahodder/8591750 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
Followup: can this be adapted so as to only sort the order of sticky posts on a theme configured to display all posts, starting with most recent, as the landing page?