WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Code below is designed for testing to see if current post is in a category that is an ancestor (child/grandchild/greatgrandchild etc) of cat number 526

$cats = wp_get_post_categories();
if (cat_is_ancestor_of($cats[0],526)) {
echo "yes this works" ;

Not sure why this isnt working but likely something stupidly simple....


share|improve this question
Just to clarify, ancestor refers to any cat UP the chain from it. So if 526 is the category, and you want to get its ancestors, that would be all the categories that have 526 as a child/grandchild, etc. That might be why the syntax is confusing in the cat_is_ancestor_of() call. – brandwaffle Dec 22 '11 at 20:12

The correct syntax of cat_is_ancestor_of is

cat_is_ancestor_of( $parent_cat_id, $child_cat_id );


$parent_cat_id: should be the id to check if this is the parent category, in your case it should be 526.

$child_cat_id: should be the id of the child category.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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