How to know if it’s a child taxonomy?

I’m in need to know if the current taxonomy is child or parent. How can i achieve this?

I need it for the condition in if statement. I need to know

Read More
if(this is child taxonomy){

}

Anybody knows how?

Related posts

2 comments

  1. You may be using this piece of code, found in the WordPress support articles and which you can see here.

  2. Use get_ancestors().

    $ancestors = get_ancestors( 4, 'category' );
    // var_dump($ancestors); // debugging
    if (!empty($ancestors)) {
      // category 4 is a child of some other category
    } else {
      // category 4 is not a child. It is "top-level" in the hierarchy.
    }
    

Comments are closed.