Advertisements

get_term_children

Definition:
function get_term_children( $term_id, $taxonomy ) {}

Merge all term children into a single array of their IDs.
This recursive function will merge all of the children of $term into the same array of term IDs. Only useful for taxonomies which are hierarchical.

Parameters

  • string $term_id: ID of Term to get children
  • string $taxonomy: Taxonomy Name

Return values

returns:List of Term Objects. WP_Error returned if $taxonomy does not exist

Source code

function get_term_children( $term_id, $taxonomy ) {

	if ( ! taxonomy_exists($taxonomy) )

		return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));



	$term_id = intval( $term_id );



	$terms = _get_term_hierarchy($taxonomy);



	if ( ! isset($terms[$term_id]) )

		return array();



	$children = $terms[$term_id];



	foreach ( (array) $terms[$term_id] as $child ) {

		if ( isset($terms[$child]) )

			$children = array_merge($children, get_term_children($child, $taxonomy));

	}



	return $children;

}

1755

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: