Skip to content

Instantly share code, notes, and snippets.

@pedrorvidal
Last active August 29, 2015 13:56
Show Gist options
  • Save pedrorvidal/9188718 to your computer and use it in GitHub Desktop.
Save pedrorvidal/9188718 to your computer and use it in GitHub Desktop.
Pegar uma custom taxonomy e mostrar ela ordenada com filhos agrupados.
<?php
$taxonomyName = "slug-da-minha-taxonomia";
$terms = get_terms($taxonomyName,array('parent' => 0));
foreach($terms as $term) :
echo '<a href="'.get_term_link($term->slug,$taxonomyName).'">'.$term->name.'</a>';
$term_children = get_term_children($term->term_id,$taxonomyName);
echo '<ul>';
foreach($term_children as $term_child_id) :
$term_child = get_term_by('id',$term_child_id,$taxonomyName);
echo '<li><a href="' . get_term_link( $term_child->name, $taxonomyName ) . '">' . $term_child->name . '</a></li>';
endforeach;
echo '</ul>';
endforeach;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment