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?
- Can I force WP_Query to return no results?
- Get WooCommerce best selling products for the current month [closed]
- How to filter by category in REST API, excluding posts also in other category term?
- retrieve thumbnail from post ID of best selling product in category
- Woocommerce query by price range and custom meta key
- How to order category.php loop by ‘meta_value’?
- How can I display recent posts from a particular category in my header?
- Custom search form with empty parameters
- Find all product that contain terms with %keywords% in WP_Query
- WP Query – Get WooCommerce Products with variation that is in stock
- Multiple search queries on one page
- How get posts from a subcategory of a category by name?
- Get image of latest post from taxonomies/categories
- Including only current user’s posts in search
- WP_Query arguments to fetch custom post type posts which are in certain category?
- Custom category search box for WordPress
- How do I reset this wp_list_categories query?
- Refine search results using WP_Query
- Search Posts with Custom Fields as query
- How to show subcategories using loop?
- Assigning a meta_query value based on regexp to wp_query fails
- Remove a specific category ID from related post
- Complex Category selection as per user input
- Get all products which have both product category
- How to get all unique categories for posts in loop?
- wp_query ‘s’, search filter with pagination is not working
- Display Featured Post by Categories and Avoid duplicated posts
- WP_QUERY to display woocommerce products whose author IS the logged in user
- Display filtered results into custom page
- WooCommerce – get product sub categories
- Cutom wp_query for geolocation search, pagination not working
- Out Of memory issue on post per page parameter
- query_vars overriding WP_Query args
- how can I override The Events Calendar query modifications?
- Check if loop has any categories?
- Inserting HTML to close and open divs in WP_Query loops
- How do I get my custom query to work with search results after the first page?
- Need Sub-category with main Category
- Woocommerce pagination and result count after custom loop
- Replacing search results with custom external query
- Prevent author bio page from showing in search results
- Combine results of multiple WP_Query to resemble single WP_Query
- Can’t fetch Custom Post Type Data through Custom Query
- How do I get Woocommerce product variation name and variation description in a WP_Query?
- Slow Query On Search
- How To Keep Search Title the same on paged Results
- How to get posts by category and by choosing a taxonomy term?
- 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
- Can I make a search query which includes a space?
- Widgets: Show Recent Posts Only if the Posts Have Both Categories X and Y
- get_the_terms has strange result since version 6.0
- Filter products on category AND tag
- My combination of ‘post_type’ and ‘tax_query’ not working?
- WP_Query no result if keyword contains number
- WooCommerce WP_Query using tax_query returns no results (0 = 1)
- How sort products by calculate value? ( custom post meta, price, option)
- wc_get_products() return empty object
- WooCommerce. How To Exclude Subcategory Products From Category Listing Page
- get_posts return only first result
- Related categories order posts by category
- Display All Top Child Categories / Taxonomy
- update_post_meta performance in a loop woocommerce
- update_post_meta performance in a loop woocommerce
- getting posts by tags
- Query child posts with tax query on parents
- Custom Post Type WP_Query with filters and search
- Search has query that will return no results
- Get posts by similar names and categories
- Show posts from categories instead of tags
- How do i query woocommerce booking post type on init action?
- Woocommerce orderby rand with tax_query not random
- query.php – multiple is_category functions
- Create multiple sections for all categories and then queries all the posts for each of those categories
- $wp_query when new WP_Query
- Filter posts by category
- WordPress WP_Query Search (‘s’) With Multiple Search Terms
- Search results stuck on page 1
- Custom Taxonomy in custom REST API search
- Pagination only showed when no category is set in wp_query
- Using WP Query, I want to include all posts in category 1 as long as they are not also in category 2