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.

Return

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

Usage

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.

Code of cat_is_ancestor_of: wp-includes/category.php VER 4.9.8

<?php
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
    Hello, !     Log In . Register