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

if(this is child taxonomy){


Anybody knows how?


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

  • 1
    please do not post link-only answers, see how to answer. – Milo Aug 27 '13 at 14:30

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.

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.