G
G
Genri_Rus2020-02-08 17:44:27
WordPress
Genri_Rus, 2020-02-08 17:44:27

How to display subcategories of the 2nd level?

There is a 3-level nesting for the categories

Clothes and shoes:
-Men:
-Clothes
-Shoes
-Women:
-Clothes
-Shoes

In this case, men and women
I got the current category like this:

$current_cat  = get_queried_object();
$parent_cat = $current_cat->term_id;
$children_categories = get_term_children( $parent_cat, 'product_cat' );
if ( $children_categories ) { 
foreach($children_categories as $child_category) {
$term = get_term( $child_category, 'product_cat' );
print_r($term);
}

But in this case, I display all categories: clothes and shoes
How to display only 2-level subcategories for clothes and shoes - men and women?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question