cat_is_ancestor_of() WordPress Function

The cat_is_ancestor_of() function is used to check if a given category is an ancestor of another given category. This is useful for taxonomy queries.

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.


Top ↑

Parameters

$cat1

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

$cat2

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


Top ↑

Return

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


Top ↑

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.

Top ↑

Source

File: wp-includes/category.php

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


Top ↑

Changelog

Changelog
VersionDescription
2.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.