Hi,
We have a search form with multiple filter...
We want to exclude some terms from the search result...
Ex.:
CARS
- Honda
- Toyota
- Hyundai
- Kia
Si we search in taxonomy CARS but we want to exclude Toyota and Hyundai
In image attached it's the wpv-mobilier taxonomy that we want to exclude some terms
Is it possible to do?
Thanks
Luo Yang
Supporter
Languages:
Englisch (English )
Vereinfachtes Chinesisch (简体中文 )
Timezone:
Asia/Hong_Kong (GMT+08:00)
Hi Jean,
Please try Views filter hook wpv_filter_query, like this:
Add codes in your theme/functions.php:
add_filter( 'wpv_filter_query', 'exclude_terms_func', 10, 3 );
function exclude_terms_func($query, $setting, $views_ID)
{
if($views_ID == 123)
{
$query['tax_query'][] = array(
'taxonomy' => 'mobilier',
'field' => 'slug',
'terms' => array( 'toyota', 'hyundai' ),
'operator' => 'NOT IN'
);
$query['tax_query']['relation'] = 'AND';
}
return $query;
}
Please replace 123 with your views post ID, replace "mobilier" with your custom taxonomy slug
More help:
https://toolset.com/documentation/user-guides/views-filters/wpv_filter_query/
This is great! I was able to change the Operator to "In" to only include specific terms. The best thing about this snippet is that I can still use the Query Filter option for the parametric search. Thanks!