Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.