WordPress at a glance

cat_is_ancestor_of() WP 1.0

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.

Works based on: term_is_ancestor_of()
✈ 1 time = 0.000757s = slow | 50000 times = 1.05s = fast | PHP 7.0.5, WP 4.5.1

No Hooks.


true/false. Whether $cat2 is child of $cat1


cat_is_ancestor_of( $cat1, $cat2 );
$cat1(int/object) (required)
ID or object to check if this is the parent category.
$cat2(int/object) (required)
The child category.


Since 2.1.0 Introduced.

Code of cat is ancestor of: wp-includes/category.php WP 5.4.2

function cat_is_ancestor_of( $cat1, $cat2 ) {
	return term_is_ancestor_of( $cat1, $cat2, 'category' );

Related Functions

From tag: Relations (of posts terms...)

More from tag: Conditional tags (all)

More from category: Categories

No comments
        Log In . Register