Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsjusteileen/eed028876e87d1dc2b82bdff157cbf8c to your computer and use it in GitHub Desktop.
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
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