Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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>';
}
share|improve this answer
    
Thats exactly what I was looking for! I love you mate! –  Toni Michel Caubet Aug 19 '13 at 18:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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