query_vars['post_type']) && $query->query_vars['post_type'] == 'artist' ) { $query->set('orderby', 'meta_value'); $query->set('meta_key', 'sortname'); $query->set('order', 'ASC'); } // return return $query; } add_action('pre_get_posts', 'my_pre_get_posts'); // Exclude Pages from Search Results function search_filter($query) { if ( ! is_admin() && $query->is_main_query() ) { if ( $query->is_search ) { $query->set( 'post_type', 'post' ); } } } add_action( 'pre_get_posts', 'search_filter' ); /** * This function modifies the main WordPress query to include an array of * post types instead of the default 'post' post type. * @param object $query The main WordPress query. */ function include_custom_post_types_in_search_results( $query ) { if ( $query->is_main_query() && $query->is_search() && ! is_admin() ) { $query->set( 'post_type', array( 'post', 'artist' ) ); } } add_action( 'pre_get_posts', 'include_custom_post_types_in_search_results' );