Definition:
function cat_is_ancestor_of( $cat1, $cat2 ) {}
Check if a category is an ancestor of another category.
You can use either an id or the category object for both parameters. If you use an integer the category will be retrieved.
Parameters
- int|object $cat1: ID or object to check if this is the parent category.
- int|object $cat2: The child category.
Return values
returns:Whether $cat2 is child of $cat1
Source code
function cat_is_ancestor_of( $cat1, $cat2 ) { if ( ! isset($cat1->term_id) ) $cat1 = &get_category( $cat1 ); if ( ! isset($cat2->parent) ) $cat2 = &get_category( $cat2 ); if ( empty($cat1->term_id) || empty($cat2->parent) ) return false; if ( $cat2->parent == $cat1->term_id ) return true; return cat_is_ancestor_of( $cat1, get_category( $cat2->parent ) ); }
589
No comments yet... Be the first to leave a reply!