cat_is_ancestor_of

Check if a category is an ancestor of another category.

Description

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

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

Parameters (2)

0. $cat1 (int|object)
ID or object to check if this is the parent category.
1. $cat2 (int|object)
The child category.

Usage

  1. if ( !function_exists( 'cat_is_ancestor_of' ) ) { 
  2. require_once ABSPATH . WPINC . '/category.php'; 
  3.  
  4. // ID or object to check if this is the parent category. 
  5. $cat1 = null; 
  6.  
  7. // The child category. 
  8. $cat2 = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = cat_is_ancestor_of($cat1, $cat2); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/category.php  
  1. function cat_is_ancestor_of( $cat1, $cat2 ) { 
  2. return term_is_ancestor_of( $cat1, $cat2, 'category' );