Exclude term from search query
-
Hello,
I have a website with listings ( custom post type) with some taxonomies, like:
– woningtype
– interieur, etc..
On some pages I have a search function which uses the taxonomy ‘Woningtype’ with
the terms:
– Shortstay
– Verhuur
– TestI want to exclude now the term ‘Test’ from the search function; i.d. don’t show the term ‘Test’
with the search parameter ‘Woningtype’.I am now using the following code in the file functions.php:
function be_modify_search_query( $query ) { global $wp_the_query; if( $query === $wp_the_query && $query->is_search() ) { $tax_query = array( array( 'taxonomy' => 'woningtype', 'field' => 'slug', 'terms' => 'test', 'operator' => 'NOT IN', ) ); $query->set( 'tax_query', $tax_query ); } } add_action( 'pre_get_posts', 'be_modify_search_query' );
[Code moderated: please ensure that your code is enclosed in backticks (`) or use the code button.]
It still doesn’t work! Somebody has a idea?
The website is: https://www.kennethweb.nlThanks,
Kenneth
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Exclude term from search query’ is closed to new replies.