W3cubDocs

/WordPress

cat_is_ancestor_of( int|object $cat1, int|object $cat2 )

Checks if a category is an ancestor of another category.

Description

You can use either an ID or the category object for both parameters. If you use an integer, the category will be retrieved.

Parameters

$cat1

(int|object) (Required) ID or object to check if this is the parent category.

$cat2

(int|object) (Required) The child category.

Return

(bool) Whether $cat2 is child of $cat1.

More Information

  • The function evaluates if the second category is a child of the first category.
  • Any level of ancestry will return True.
  • Arguments should be either integer or objects; if arguments are string representations of integers and not true integers, cat_is_ancestor_of will return False.

Source

File: wp-includes/category.php

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

Changelog

Version Description
2.1.0 Introduced.

© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/cat_is_ancestor_of