Answer the question
In order to leave comments, you need to log in
How to get parent category slug regardless of nesting?
I have a parent category Clothes and shoes
It has 2 subcategories
Men
-Clothes
-Shoes
Women
-Clothes
-Shoes
I get categories like this:
$current_category = get_queried_object();
$args_category = [
'taxonomy' => $current_category->taxonomy,
'parent' => $current_category->term_id,
'hide_empty' => false,
];
$terms = get_terms( $args_category );
if ( $terms ) {
foreach ( $terms as $term ) {
if ( $term->parent > 0 ) {
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question