Skip to content

Instantly share code, notes, and snippets.

@revaboogy
Forked from jo-snips/event-category-list.php
Last active August 29, 2015 13:56
Show Gist options
  • Save revaboogy/9117002 to your computer and use it in GitHub Desktop.
Save revaboogy/9117002 to your computer and use it in GitHub Desktop.
Category list with child categories for Wordpress Events
<?php
$terms = get_terms("tribe_events_cat", array(
'parent' => 0,
));
//print_r ($terms);
// $terms = ($terms [parent] => 0 );
$count = count($terms);
if ( $count > 0 ){
echo '<ul class="events-cat-menu">';
?>
<?php foreach ( $terms as $term ): ?>
<li class="cat_<?php esc_attr_e($term->slug); ?>"><a href="<?php get_term_link($term->slug, 'tribe_events_cat'); ?>"><?php esc_html_e($term->name); ?></a>
<ul>
<?php
// get children
$kids = get_terms('tribe_events_cat', array(
'parent'=>$term->term_id,
));
foreach ( $kids as $kid) {
echo '<li class="cat_'. $kid->slug .'"><a href="'. get_term_link($kid->slug, 'tribe_events_cat') .'">' . $kid->name . '</a></li>';
}
?>
</ul>
</li>
<?php endforeach; ?>
<?
echo '</ul>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment