I am hoping someone can help me out here. Looking for a solution to filter pre_get_posts where I have multiple posts types and one of those post types needs a meta filter.
My current filter is as follows:
function mta_search_filter($query) {
if ( !is_admin() && $query->is_main_query() ) {
if ($query->is_search) {
$query->set('post_type', array('project', 'people', 'post'));
$query->set('meta_key', 'list_only');
$query->set('meta_value', '1');
}
}
}
add_action('pre_get_posts','mta_search_filter');
The problem above is that it applies the meta filter to all of the posts types. Unfortunately that meta_key does not apply to the others. Only projects.
Is there a way to do a meta_key on just projects?
I asked the question on SE with no luck so far:
https://wordpress.org/support/topic/querying-two-custom-fields-in-custom-post-type