Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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....

TIA

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
add comment

1 Answer 1

The correct syntax of cat_is_ancestor_of is

cat_is_ancestor_of( $parent_cat_id, $child_cat_id );

Where:

$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
add comment

Your Answer

 
discard

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.