Codex tools: Log in
Contents |
Merge all term children into a single array.
This recursive function will merge all of the children of $term into the same array. Only useful for taxonomies which are hierarchical.
Will return an empty array if $term does not exist in $taxonomy.
<?php get_term_children( $term, $taxonomy ) ?>
Used to get an array of children taxonomies and write them out with links in an unordered list.
<?php
$termID = 10;
$taxonomyName = "products";
$termchildren = get_term_children( $termID, $taxonomyName );
echo '<ul>';
foreach ($termchildren as $child) {
$term = get_term_by( 'id', $child, $taxonomyName );
echo '<li><a href="' . get_term_link( $term->name, $taxonomyName ) . '">' . $term->name . '</a></li>';
}
echo '</ul>';
?>
This would return something like.
<ul> <li><a href="link_to_term_page">Term 1</a></li> <li><a href="link_to_term_page">Term 2</a></li> </ul>
Since: 2.3.0
get_term_children() is located in wp-includes/taxonomy.php.
Terms: is_term(), term_exists(), get_term(), get_term_by(), get_term_children(), get_terms(), sanitize term(), wp_get_object_terms()