Return to Snippet

Revision: 17196
at August 26, 2009 15:15 by cyberhobo


Initial Code
function in_subcategory( $cat_id ) {
	$subcats = get_term_children( $cat_id, 'category' );
	if ( $subcats && !is_wp_error( $subcats ) ) {
		foreach( $subcats as $child_category ) {
			if( in_category($child_category) ) {
				return true;
			}
		}
	}
	return false;
}

Initial URL
http://codex.wordpress.org/Function_Reference/get_term_children

Initial Description
Usually use in a template with `in_category()`, like `if ( in_category( 3 ) || in_subcategory( 3 ) ) { ...`. Tested in WP 2.8.4.

Initial Title
WordPress: in subcatory?

Initial Tags
wordpress, category

Initial Language
PHP