Function: get_term_children

get_term_children( integer $term_id, string $taxonomy )

Merge all term children into a single array of their IDs.

Shortcut: gtc

You can use above key combination to trigger the associated snippet for this function in the WordPress Snippets for Visual Studio Code extension. You can also use this shortcut to search for this function on this website.

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.

Will return an empty array if $term does not exist in $taxonomy.

Parameters

Name Type(s) Default Value Description
$term_id integer

ID of Term to get children.

$taxonomy string

Taxonomy Name.

Returns

array | WP_Error

List of Term IDs. WP_Error returned if $taxonomy does not exist.

WordPress Developer Newsletter

Stay informed of new chapter releases, important WordPress API updates and more.