I am using this code to fetch a list of child taxonomies. I want the order displayed to be alphabetical, but it is not! Any help in figuring out how to do it? I guess ordering it before returning it will be most optimal?


$termID = 4;
$taxonomyName = "location";
$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>';

1 Answer 1


If you use the more generic get_terms you can include in the $args field all of the information to get the term or the children and specifically say what you want to order by and how you want it to be ordered.


$termchildren = get_terms( "location",
                                   'child_of' => 4,
                                   'orderby' => 'name',
                                   'order' => 'ASC'

child_of: Get all descendents of this term. Default is 0. Make sure you use an integer value. Like 1, 2, 3, 4 and not '1', '2', '3', '4'.

parent: Get direct children of this term (only terms whose explicit parent is this value). If 0 is passed, only top-level terms are returned. Default is an empty string.

  • thanks for the code but when I sub in your string for $termchildren nothing loads in at all. Any idea why it won't work in context of my code example above?
    – Redwall
    Commented Nov 21, 2012 at 8:01
  • The child_of argument expects an integer, not a string. Try substituting '4' with 4.
    – David Gard
    Commented Aug 8, 2013 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.