function exclude_product_category( $query ) {
if ($query->is_search()) {
$tax_query = (array) $query->get('tax_query');
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array('excluded-category'),
'operator' => 'NOT IN'
);
$query->set('tax_query', $tax_query);
}
return $query;
}
Related Posts:
- Using pre_get_posts to rewrite search query to display posts from multiple taxonomies
- How to add custom taxonomy to search
- Search by type posts and taxonomy
- Custom Taxonomy Not Working When added to WordPress Search
- Removing “s” from search with custom parameters
- Amend taxonomy to search in wordpress admin
- Include attachments with a custom taxonomy in search
- Hide empty categories on widget
- How to get WooCommerce Product Category Link by ID?
- Include and Exclude Taxonomies From Archives & Feeds Using ‘pre_get_posts’
- WordPress database error: [Not unique table/alias: ‘wp_postmeta’]
- pre_get_posts with tax_query causes empty result
- WordPress Search – display taxonomy terms in results
- How to find taxonomy name using only taxonomy TERM ID (or taxonomy term name)
- pre_get_posts OR relation between taxonomy and author
- Sort posts by number of matched terms
- tax_query not working on main query
- Approach for saving a product attribute values with a custom UI in a woocommerce+dokan set up [closed]
- Set download limit and expiry for WooCommerce downloadable products in specific categories
- Building an Advanced Search (text, tags, category, custom fields) – Getting the wrong SQL query
- Taxonomy , subtaxonomy,child taxonomy of a product woocommerce
- Woocommerce custom taxonomies page
- Taxonomy.php issue with search and filters
- Extending wordpress search to include excerpts and taxonomies?
- How to filter WordPress search, excluding post in some custom taxonomies?
- how to search in custom fields & custom taxonomy for custom search
- Outputting an array of term meta values in a custom WooCommerce tab?
- How do I sort posts by custom taxonomy?
- Programatically added attribute, set to ‘show on product page’ automatically. Woocommerce [closed]
- Top level parent taxonomy ID
- Woocommerce product search result layout page
- Filter WooCommerce admin products list by a custom taxonomy
- showing all search result in one template
- Catchable fatal error on custom category post
- Get custom category image from menu
- Creating a custom search form
- How to implement custom search with input fields?
- orderby meta_value breaks taxonomy term archives
- How do I keep the page I’m on within the URL when running a search on a taxonomy?
- Add multiple taxonomy filters to edit.php that support search
- Hide product categories and taxonomy terms in menu if empty
- Display related products based on 2 specific product attributes values in WooCommerce
- How to target parent product category and its children using WooCommerce?
- Extend & Search Native WordPress Image Galleries With Tags and Taxonomies?
- WordPress Tag or Custom Taxonomy Return All Posts if has that Word in Post Title
- woocommerce custom product category template
- Search Tool only refreshes Page without showing results
- WordPress thinks my custom taxonomy pages are search pages #seo
- Hiding taxonomies with no children WP_Query & tax_query
- Custom URLs in Custom Search Results
- Search Query for Multiple Terms In Same Taxonomy
- Use an HTML Element To Filter Taxonomies In WP Search
- How to display ACF taxonomy checkbox links on WooCommerce product category archive
- Why isn’t the ‘no results’ being shown when a query returns no results?
- Hide custom Woocommerce taxonomies when empty
- Clean Custom URL for Serach + Custom Taxonomy
- Advanced search redirecting to another page then filter further
- Add attribute taxonomy through code don’t appear in admin product page
- Search only custom taxonomies
- WordPress autocomplete search with taxonomies
- pre_get_posts post_meta event
- Geographic search with taxonomy structure [duplicate]
- search using multiple taxonomies and keyword
- Multiple Drop-Down custom taxonomies search
- Filter with two id of the same value CPT UI(taxanomies)
- Include get_term_link inside search
- $wp_query->found_posts not returning correct value
- Product custom taxonomy is not found when space in name
- Showing custom taxonomy in woocommerce signle product page
- Main query disturb pre_get_post by category query
- Adding term to a custom taxonomy based on term from product category
- Add terms to a taxonomy archive from within the same taxonomy
- Rewrite Search URL Permalink For CPT Custom Taxonomies
- Warning: Undefined variable $post in C:\xampp\htdocs\… after PHP upgrade
- Search custom taxonomy via query-string?
- Admin only taxonomies?
- Fill New Taxonomies
- Infinite Scroll appending Next Product Category Term pages
- Cloning product not copying custom taxonomies
- Check if any available product has specific attribute
- how to show product custom taxonomies in woocommerce rest api
- Pre_get_post custom taxonomy combined with custom fields?
- WordPress search form and search result through ACF field in custom taxonomy
- WordPress custom taxonomies new/edit post autocomplete
- Get user created Woocommerce attributes ( taxonomies ) [closed]
- Custom order of taxonomy using wp_get_object_terms and woocommerce_term_meta
- How do you search for a post by custom taxonomy?
- Custom taxonomy displayed in search results
- How to perform a search inside a specific taxonomy category
- Exclude 2 in 3 terms of A Taxonomy from all Archives
- Can I use $query->set() (in a pre_get_posts() hook) with a custom taxonomy in WP 3?
- Custom Taxonomy, shows empty value (home page of website)
- Advanced WordPress search form based on custom taxonomy and custom meta value
- Display woocommerce product_cat child terms with thumbnails
- Custom Search only for my Custom Taxonomy Page – data
- Woocommerce – how to get and display selected variations on single product page
- Search and filter with custom field in taxonomy
- Custom taxonomy with custom meta value is not sorting correctly (query returns the same value for orderby regardless of sort column click)
- How do I check if a post has a term with a particular ancestor/parent?
- Creating a custom archive page for WooCommerce products based on tags