Fires after the query variable object is created, but before the actual query is run.
pre_get_posts
add_action( 'pre_get_posts', 'kpry_change_sort_order' );
function kpry_change_sort_order( $query ) {
if ( is_archive() ) {
// If you wanted it for the archive of a custom post type use:
is_post_type_archive( 'condition' );
//Set the order ASC or DESC
$query->set( 'order', 'ASC' );
//Set the orderby
$query->set( 'orderby', 'title' );
}
};
// REORDER INJURY_CONDITION POST TYPE TO SORT ALPHABETICALLY
add_action( 'pre_get_posts', 'kpry_change_sort_order' );
function kpry_change_sort_order( $query ) {
if( (is_post_type_archive( 'injury_condition' ) ) && $query->is_main_query() ) {
$query->query_vars[ 'orderby' ] = 'name';
$query->query_vars[ 'order' ] = 'ASC';
}
}