to all i have tried by this code to sort my list custom post type by a specific category in ASC way: (i have "model" custom post type and i wanna show order by "model-year" taxonomy
function my_pre_get_posts( $query ) {
// do not modify queries in the admin
if( is_admin() ) {
return $query;
}
// only modify queries for 'model' post type
if ( $query->is_tax( 'model-year' ) && $query->is_main_query() ) {
$query->set('orderby', 'meta_value');
$query->set('meta_key', '');
$query->set('order', 'ASC');
}
// return
return $query;
}
add_action('pre_get_posts', 'my_pre_get_posts');