G
G
Genri_Rus2020-02-09 18:57:17
WordPress
Genri_Rus, 2020-02-09 18:57:17

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 ) {
    
   }
  }
}

How can I get the name (slug) of the parent category for clothes and shoes, regardless of nesting?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pychev Anatoly, 2020-02-09
@Genri_Rus

$current_category->slug;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question