Skip to content

Instantly share code, notes, and snippets.

@wpchannel
Created August 19, 2018 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpchannel/b9ffce61137a113ba31d90385d623068 to your computer and use it in GitHub Desktop.
Save wpchannel/b9ffce61137a113ba31d90385d623068 to your computer and use it in GitHub Desktop.
List children terms of current taxonomy term
<?php
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
$taxonomy_name = 'category';
$term_children = get_term_children($term_id, $taxonomy_name);
echo '<ul class="nav nav-pills">';
foreach ($term_children as $child) {
$term = get_term_by('id', $child, $taxonomy_name);
echo '<li><a class="btn btn-default" href="' . get_term_link($child, $taxonomy_name) . '">' . $term->name . '</a></li>';
}
echo '</ul>';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment