Set include_children
to false in the tax_query.
$args = array(
'post_type' => array( 'product', 'product_variation' ),
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'shop', 'cat1' ),
'include_children' => false,
'operator' => 'AND',
)
)
);
See https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
Related Posts:
- Query WooCommerce orders where meta data does not exist
- WP_Query for WooCommerce Products
- how to retrieve specific product attribute value in an sql query?
- merge two query arguments into one WP_Query call
- Woocommerce Get Orders By Meta Value
- Create global array to compare inside a query
- Using the same WP_Query for shop and widgets in WooCommerce shop
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise
- Wp get all the sub pages of the parent using wp query
- Usage of the new “posts_clauses” filter in WordPress 3.1?
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- How to uniquely identify queries?
- Get posts by meta data OR title
- WP_Query ordered by custom field that is a date string?
- How to make an activities stream mixing posts and comments?
- Duplicate Queries
- How to query for a week using key => value WP_Query argument notation?
- SQL query equivalent to WP User Query
- WooCommerce: filter by parent product’s taxonomy and product variation’s meta data
- How to count post type that has a particular term?
- Retrieve products with specific attribute and in category – woocommerce
- Foreach-generated custom tax queries, each with an ajax “Load more” button
- Display featured products through custom loop in WooCommerce 3 [closed]
- meta_query on a date range using an array of values
- WP_Query Performance Issues with meta_query
- How to detect custom query inside `posts_where` hook?
- Is temporarily overwriting $wp_query a bad idea?
- Query Set Order By Author
- Get product list of given category
- How to exclude products by tag from woocommerce shop page?
- How to output different posts per page?
- WooCommerce Only OnSale Products Loop Snippet [closed]
- Pass array of taxonomy terms to wp_query
- How to orderby meta_value_num with dollar ($) sign
- Using WP_Query in “parse_query” or “pre_get_post” in Posts2Posts
- Query: offset post list, unless it’s a specific category
- How to reduce the number of queries?
- List of the years with posts presented
- Sort query by author: 1 author, then others
- Custom Query num_rows returns wrong amount
- Overwrite YoastSEO meta-tags with another page’s [closed]
- Take all produts by category
- How to orderby multiple meta fields if some fields are empty
- How to get all product attributes for filters in WooCommerce?
- How to duplicate 5 posts out of WP_Query results?
- WP_query sorting can’t sort danish letters (æ, ø, å)
- Slow queries on a huge database
- WP_Query with ‘rand’, but equal number of posts from the taxonomy terms given
- Multisite pagination issue by multi query archive 404
- Query with relation and one without relation using multiple taxonomies?
- Sort WordPress Posts Meta value by Week not Day
- 2 wordpress loops showing 1 post from same post type – how to avoid showing the same post?
- Transient api Caches confused
- How can I override one post and make it display content for another post?
- Get multiple users with meta value in one query and populate WP_User class
- How to order WP_Query to group results?
- Redirect Search to Form When No Product Results Are Found
- How to display SQL query that ran in WC_Order_Query?
- WP_Query Taxonomy categories filtering
- Query where ANDing slug values not working
- Woo Commerce using WP_Query to get products that match price range, with an additional required product attribute
- How to filter query loop block with a search string from the query parameters
- Assign a minimum result count for WooCommerce query shortcodes?
- Woocommerce: order posts by meta key
- Unlimited Page Sitemap Link
- How to SQL query posts IDs by categories AND authors?
- $wp_query->found_posts not returning correct value
- Post incorrectly excluded when using “category__in”?
- Query multiple post types, but different order for each
- Display posts ONLY from the current logged in user and current week/year/month Elementor posts
- Make a products only viewable to a specific user ID in meta_query pre_get_posts
- ElasticPress is (aparently) messing with my search filters
- Any way to use FETCH_KEY_PAIR with $wpdb?
- What code to use in an array to call the current sub-category?
- Get categories within specific term
- Query against multiple locations within single custom post type post
- How to get_comments() ordered by date and parent?
- WP Query. Ordering posts by another post types meta
- Woocomerce – Order products by float attribute in archive pages
- Not able to fetch woocommerce variation sales products for particular category products
- How to make a search query if not found in post table then search in postmeta table?
- Adding Category in WP_Query Not Working
- WP_Query to Retrieve Posts from WooCommerce Products that are Only in Catalog
- Merge two queries and remove duplicate
- Woocommerce WP_Query post__not_in problem
- how to show more than 1 post into three columns query
- How can I get all the posts that are related with a specific taxonomy term?
- Fetch only categorized posts
- Custom pagination (Title, date and teaser)
- Pagination in custom query in a category page
- Get a list of the last posts grouped by author and filtered by category
- When should you use WP_Query vs query_posts() vs get_posts()?
- How to query post ids liked by the Author
- Modify query after meta value
- Showing posts from 4 categories along with all latest posts
- Pagination in WP query with transient API
- Main loop querying current template’s info only in custom category archive pages, not my posts
- Use meta query only 3 or more results?
- Search results stuck on page 1
- Use value from meta key array for use in WP_Query