function searchExcludePages($query) {
if ($query->is_search) {
$query->set('post_type', 'ait-dir-item');
}
return $query;
}
add_filter('pre_get_posts','searchExcludePages');
function searchExcludePages($query) {
if ($query->is_search) {
$terms = get_terms( array( 'taxonomy' => 'ait-dir-item-category' ) );
$to_exclude = array();
foreach ( $terms as $term ) {
$to_exclude[] = $term->term_id;
}
$tax_query = array(
array(
'taxonomy' => 'ait-dir-item-category',
'terms' => $to_exclude,
'operator' => 'NOT IN'
)
);
$query->set('tax_query', $tax_query);
}
}
add_filter('pre_get_posts','searchExcludePages');
function searchExcludePages($query) {
if ($query->is_search) {
$query->set('post_type', 'ait-dir-item');
$taxquery = array([
'post_type' => 'ait-dir-item',
'taxonomy' => 'ait-dir-item-category',
'field' => 'slug',
'operator' => 'NOT IN',
]);
$query->set( 'tax_query', $taxquery );
}
return $query;
}
add_filter('pre_get_posts','searchExcludePages');