Skip to content

Instantly share code, notes, and snippets.

@UVLabs
Created April 7, 2016 21:48
Show Gist options
  • Save UVLabs/6e91df04d1991fd932bd1e1cb1f9288f to your computer and use it in GitHub Desktop.
Save UVLabs/6e91df04d1991fd932bd1e1cb1f9288f to your computer and use it in GitHub Desktop.
This snippet gets all categories including it's children, snippet could be easily customized to customize output. Change 'course' in get_terms() to get custom post type of choice.
<?php
$parent = get_terms( 'course', 'parent=0&hide_empty=0');
foreach( $parent as $cat_parent ){
echo '<div class="courses-container" style="float: left; border: 1px solid;">';
echo '<h2><a href="' . get_term_link( $cat_parent ) . '">'.$cat_parent->name.'</a></h2>';
$term_id = $cat_parent->term_id;
$taxonomy_name = 'course';
$termchildren = get_term_children( $term_id, $taxonomy_name );
echo '<ul class="course-child">';
foreach ( $termchildren as $child ) {
$term = get_term_by( 'id', $child, $taxonomy_name );
echo '<li><a href="' . get_term_link( $child ) . '">' . $term->name . '</a></li>';
}
echo '</ul>';
echo '</div>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment