Title: Function like &#039;is_child_of_category&#039;
Last modified: August 19, 2016

---

# Function like 'is_child_of_category'

 *  Resolved [superuntitled](https://wordpress.org/support/users/superuntitled/)
 * (@superuntitled)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/function-like-is_child_of_category/)
 * I I am looking for a function that merely returns true or false. The function
   would check if the category archive being queried is a child of a particular 
   parent category. The function would look something like this (similar to the `
   is_category()` function):
 *     ```
       if(is_child_of_category('3')){ //do something }
       if(is_child_of_category('4')){ //do something else }
       if(is_child_of_category('5')){ //do something entirely different }
       ```
   
 * I have looked through the documentation and the forums but have not found any
   solutions, any ideas if this has been done or how one would go about it?
 * thanks in advance.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/function-like-is_child_of_category/#post-1716205)
 * [http://codex.wordpress.org/Function_Reference/cat_is_ancestor_of](http://codex.wordpress.org/Function_Reference/cat_is_ancestor_of)
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/function-like-is_child_of_category/#post-1716226)
 * See if this helps:
    [http://wordpress.org/support/topic/is-category-child?replies=6](http://wordpress.org/support/topic/is-category-child?replies=6)
 *  Thread Starter [superuntitled](https://wordpress.org/support/users/superuntitled/)
 * (@superuntitled)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/function-like-is_child_of_category/#post-1716244)
 * thanks, a combination of both i think:
 * first a function to get the category id:
 *     ```
       function getCurrentCatID(){
       global $wp_query;
       if(is_category() || is_single()){
       $cat_ID = get_query_var('cat');
       }
       return $cat_ID;
       }
       ```
   
 * Next use `cat_is_ancestor_of`
 *     ```
       $post = $wp_query->post;
       $id = getCurrentCatID();
   
       if ( cat_is_ancestor_of(3, $id) { include(TEMPLATEPATH . '/unique.php'); }
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Function like 'is_child_of_category'’ is closed to new replies.

## Tags

 * [custom](https://wordpress.org/support/topic-tag/custom/)
 * [function](https://wordpress.org/support/topic-tag/function/)

 * 3 replies
 * 3 participants
 * Last reply from: [superuntitled](https://wordpress.org/support/users/superuntitled/)
 * Last activity: [15 years, 7 months ago](https://wordpress.org/support/topic/function-like-is_child_of_category/#post-1716244)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
