I was able to get all the items of a custom taxonomy for a post, like this:

$args=array('orderby'=>'parent',"fields" => "all");
$term_list = wp_get_post_terms($post->ID, 'tvr_amenity', $args);

My problem is that i would like to show the tree (respecting the parents)

So i would like to get them ordered by name and parent but i cant find anything related on codex..

any idea how?


What about:

$taxName = "tvr_amenity";
$terms = get_terms($taxName,array('parent' => 0));
foreach($terms as $term) {
   echo '<a href="'.get_term_link($term->slug,$taxName).'">'.$term->name.'</a>';
   $term_children = get_term_children($term->term_id,$taxName);
   echo '<ul>';
   foreach($term_children as $term_child_id) {
       $term_child = get_term_by('id',$term_child_id,$taxName);
       echo '<li><a href="' . get_term_link( $term_child->name, $taxName ) . '">' . $term_child->name . '</a></li>';
   echo '</ul>';
  • Thats exactly what I was looking for! I love you mate! – Toni Michel Caubet Aug 19 '13 at 18:49
  • How we can show all subchildren like this? – Alexandros Jan 30 '17 at 14:46
  • @Alexandros All subchildren of what? – Angelique Jan 30 '17 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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