Created
          May 6, 2014 09:43 
        
      - 
      
 - 
        
Save jdhobbsuk/4bded33f4803c3be4363 to your computer and use it in GitHub Desktop.  
    is_child_term()
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // is_child_term() | |
| // ------------------------------------------------------------- | |
| function is_child_term($taxonomy, $parent_id){ | |
| $child_terms = get_term_children( $parent_id, $taxonomy ); | |
| $response = false; | |
| foreach ( $child_terms as $term ): | |
| if(is_tax($taxonomy, $term)): | |
| $response = true; | |
| endif; | |
| endforeach; | |
| return $response; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
This snippet adds to the plethora of Conditional Tags that WordPress already has, but for some reason doesn't have this one.
Put simply, this function works much like
is_tax(), but checks whether the current taxonomy term is a child of a specific taxonomy term. It's to be used withintaxonomy-[name].phpfile, so you can tweak the layout within without creating separate theme files (taxonomy-[name]_[term].php). You'll most likely use it alongsideis_tax().I needed this because I needed to supply a completely different looking loop for a Videos section, and any of its sub terms.