Skip to content

Instantly share code, notes, and snippets.

@rakeshr
Created September 20, 2011 16:49
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 rakeshr/1229634 to your computer and use it in GitHub Desktop.
Save rakeshr/1229634 to your computer and use it in GitHub Desktop.
wordpress - list main terms and sub terms under it
<?php
//list terms in a given taxonomy
$taxonomy = 'apptypes';
$appargs=array(
'hide_empty' => false,
'orderby' => 'name',
'order' => 'ASC',
'parent' => '0'
);
$appterms = get_terms($taxonomy,$appargs);
?>
<ul>
<?php
foreach ($appterms as $appterm) {
echo '<li>' . '<a href="' . esc_attr(get_term_link($appterm, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $appterm->name ) . '" ' . '>' . $appterm->name.'</a></li>';
$termID = $appterm->term_id;
$taxonomyName = $taxonomy;
$termchildren = get_term_children( $termID, $taxonomyName );
foreach ($termchildren as $child) {
$termsub = get_term_by( 'id', $child, $taxonomyName );
echo '<ul>';
echo '<li>'.$termsub->name.'</li>';
echo '</ul>';
} }
?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment