0

On a single post, I display the post's categories like this:

  $categories = get_the_category($id);

My category hierarchy is: cat1 parent of cat2, parent of cat3, etc.

I would like to display only children categories (from cat2 to catN). I tried to use get_category_by_slug($id,'cat1') with no results...

0

For this specific question, Try this

  $categories = get_the_category($id);
  foreach($categories as $category){
        if($category->parent != 0){

         // Display it here
         echo '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '">' . esc_html( $category->name ) . '</a>';

        }
  }
  • Thanks for your answer, I'll try it and let you know asap. – supershivas Mar 22 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.