Skip to content

Instantly share code, notes, and snippets.

@amielucha
Last active August 29, 2015 14:16
Show Gist options
  • Save amielucha/922ea5d087a839d864a6 to your computer and use it in GitHub Desktop.
Save amielucha/922ea5d087a839d864a6 to your computer and use it in GitHub Desktop.
Sort posts archive by name.
function sort_archive_by_name( $query ) {
/*
* Change the 'if' condition to the taxonomy/category you want to apply the new sorting
*/
if ( is_tax('product-category') ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
}
}
add_action( 'pre_get_posts', 'sort_archive_by_name' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment