wordpress change orderby on archive page code example
Example: wp order archive page post by title
// Sort All Tours by Title
add_filter( 'parse_query', 'sorting_archives' );
function sorting_archives( $wp_query ) {
if (is_post_type_archive( 'tour' ) || is_tax()) {
$wp_query->set( 'orderby', 'title' );
$wp_query->set( 'order', 'ASC' );
}
return $wp_query;
}