Try to add the following lines of code at the end of your theme’s functions.php file:
function custom_pre_get_posts_query( $q ) {
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'uncategorized' ),
'operator' => 'NOT IN'
);
$q->set( 'tax_query', $tax_query );
}
add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );
Related Posts:
- How to query only for products with status “in stock” in WooCommerce? [closed]
- Searching through different categories on different pages code is not working
- showing all search result in one template
- Cluster WooCommerce products in each Category Archive by Tags assigned to products
- Extend product search with meta in WooCommerce
- Search Query for multiple categories using ‘OR’ but having certain categories be ‘AND’
- WordPress Custom Search Form Displaying Unexpected Results
- Redirect Search to Form When No Product Results Are Found
- WP_Query Taxonomy categories filtering
- How to echo woocommerce category name
- $wp_query->found_posts not returning correct value
- Categories In English version showing not canonical URL, instead shows query search result
- What code to use in an array to call the current sub-category?
- Get categories within specific term
- Filtering product search results using tags
- Advanced Search – Is this possible?
- wordpress search word, “hello world” ===> ‘hello+world’ ===> ‘hello’, ‘world’
- Query posts from category A, and from either category B or C
- Woocommerce – Changing the order of the upsell products [closed]
- Out Of memory issue on post per page parameter
- query_vars overriding WP_Query args
- Query with search and subscribers only output
- how can I override The Events Calendar query modifications?
- Search by post id in a specific page then auto-redirect to searched post
- Combining categories (Query posts with multiple taxonomy terms)
- Check if loop has any categories?
- Filtering out child category posts from parent category archive not working
- Search for “2nd” also returns “22nd” in wp_query
- Exclude Category filter from Portfolio section
- How to make search for posts using get method?
- Categorising search results based on Custom Fields
- Inserting HTML to close and open divs in WP_Query loops
- WooCommerce search products between price range using WP_Query
- Redirect to another page using contact form 7? [closed]
- Add filter post_where and passing post_type argument
- Limiting number of related posts
- using pre_get_posts for search results not found
- Category ‘pad_counts’ & ‘parent’ conflict
- wp_query not working with post_type
- Search posts missing a particular custom field
- How do I get my custom query to work with search results after the first page?
- Modify Search Query if original Query gave no results
- Woocommerce – exclude only older out-of-stock items
- Need Sub-category with main Category
- Woocommerce pagination and result count after custom loop
- How to query woocommerce product by pricing? [closed]
- Finding WordPress Posts assigned to multiple categories
- Include posts from some categories while excluding from others
- Include post content of linked posts in search
- Replacing search results with custom external query
- Prevent author bio page from showing in search results
- How do I amend wp_query before it is run/executed?
- wp_query search not taking keywords with together for multiple words
- Combine results of multiple WP_Query to resemble single WP_Query
- How to order WP_Query to group results?
- Wildcard search in WP Query
- Get a list of posts by specific category
- Search Page Returns Nothing
- Can’t fetch Custom Post Type Data through Custom Query
- How to properly use AND / OR in custom search
- wp_query is showing posts from other categories
- How do I get Woocommerce product variation name and variation description in a WP_Query?
- Exclude a Woocommerce product from WP_Query
- How to avoid bypass of search bar rules?
- Woo Commerce using WP_Query to get products that match price range, with an additional required product attribute
- Issues with search after added meta_query
- How to load a script code only in posts?
- How do you determine if a result in a search query is a post or a page?
- Slow Query On Search
- Multiple meta_key ordering with pre_get_posts
- Sorting search results with custom dropdown
- How To Keep Search Title the same on paged Results
- Assign a minimum result count for WooCommerce query shortcodes?
- wp_query show all values
- change posts_orderby of the callback wp_query?
- How to search for meta_query LIKE or tax_query LIKE and grab these posts on search results?
- Woocommerce: order posts by meta key
- How to display a list of posts in same child category as current post
- Slider won’t work with custom query
- var_dump of WP_Query object is not empty, while .have_posts() return false
- WP_Query with one category in args shows other categories
- Woocommerce search form with category select
- How to exclude a category name from showing?
- Loop categories by recent post
- How order posts from category by date and comment count?
- WP_Query for products always returns empty
- Get the child category ID of current category
- How to get posts by category and by choosing a taxonomy term?
- Related Posts Excluding Certain Categories
- Getting the permalink to the latest post from a category
- How to restrict search on a certain page to only return results against custom taxonomies?
- What is wrong with my WP_Query Arguments?
- Filter out a meta key in the Search results page with two CPT
- Query by key or author
- Unlimited Page Sitemap Link
- Ignore image urls in wp_query search
- Search.php – return number of results but cannot loop through
- Can I make a search query which includes a space?
- Widgets: Show Recent Posts Only if the Posts Have Both Categories X and Y
- How to filter a static post page with ajax and $wp_query