How to get_term_children output in alphabetical order?

get_term_children() only outputs the term IDs, and you later get details for each term using get_term_by(). You can combine these queries in one using get_terms() with the child_of argument:

get_terms( $taxonomyName, array( 'child_of' => $termID ) );

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 using usort(). See an example at this answer for a related problem.

Leave a Comment