How do i get output of this in alphabetical order
<?php
$termID = 5;
$taxonomyName = 'area';
$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>';
?>
get_term_children()
only outputs the term IDs, and you later get details for each term usingget_term_by()
. You can combine these queries in one usingget_terms()
with thechild_of
argument:By default this sorts by name. However, it is possible that the
child_of
argument undoes the sorting. In that case you can sort it again usingusort()
. See an example at this answer for a related problem.