Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cparkinson/2ac2555d51bed703ce2d39e14d1de699 to your computer and use it in GitHub Desktop.
Save cparkinson/2ac2555d51bed703ce2d39e14d1de699 to your computer and use it in GitHub Desktop.
Order posts in a certain category by date ASC
/*
For when there's a category of team bios.
If you create them up in alphabetical order,
then the reverse date order will retain that order
This goes in functions.php
*/
/*Order bio Posts in reverse date order, set limit at 30 posts */
function prefix_modify_query_order( $query ) {
if ( (is_main_query())
&& (is_category( $category = 'team-bios' ))) {
$query->set( 'order', 'ASC' );
$query->set('posts_per_page', 30);
}
}
add_action( 'pre_get_posts', 'prefix_modify_query_order' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment