Advertisements

cat_is_ancestor_of

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

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: