I have a search query that I'm limiting to search within a custom post type. When the content is returned I have it sorting by meta value. The post meta is a person's position.
The function below works as expected, but I need to pull the posts and sort them in a certain order.
function kg_search_filter( $query ) {
if( is_search() && ! is_admin() && $query->is_main_query() ) {
$initial = ( !empty( $_GET['pro_search_initial'] ) ) ? $_GET['pro_search_initial'] : "";
$expertise = ( !empty( $_GET['pro_search_expertise'] ) ) ? $_GET['pro_search_expertise'] : "";
$office = ( !empty( $_GET['pro_search_office'] ) ) ? $_GET['pro_search_office'] : "";
$query->set( 'post_type', array('professional') );
if( $office ) {
$query->set( 'tax-location', $office );
}
if ( $expertise ) {
$query->set( 'tax-expertise', $expertise );
}
if ( $initial ) {
$query->set( 'meta_query', array(
array(
'key' => 'professional_last_initial',
'value' => $initial,
'compare' => '='
)
));
}
$query->set( 'posts_per_page', 10 );
$query->set( 'meta_key', 'professional_position');
$query->set( 'orderby', 'meta_value');
$query->set( 'order', 'DESC');
}
}
add_filter( 'pre_get_posts', 'kg_search_filter' );
What I'm after: First show all people with a president title, then all vice presidents, then the remaining.
I know I can use multiple loops as this solution suggests, but I'm not sure how to implement the second suggestion using pre_get_posts in reference to my query.