Answer the question
In order to leave comments, you need to log in
How to display only child products of Woocommerce?
Hello! Can you please tell me how can I display only child elements in a product category without products of subcategories? That is, there are:
- Category 1
$args = array(
'posts_per_page' => -1,
'post_type' => 'product',
'orderby' => 'title',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'slug-Категория1',
)
)
);
$the_query = new WP_Query( $args );
Answer the question
In order to leave comments, you need to log in
Thank you, but a little not that) or I did not fully understand. category is the categories of posts, and I need the child elements of the woocommerce product category. Figured it out if anyone needs it:
$args = array(
'posts_per_page' => -1,
'post_type' => 'product',
'orderby' => 'title',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'SlugName',
'include_children' => 0
)
)
);
$the_query = new WP_Query( $args );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question