Skip to content

Instantly share code, notes, and snippets.

@brycejacobson
Last active October 29, 2018 16:39
Show Gist options
  • Save brycejacobson/31096a6b8f3a96164a3c03bc62dd6e88 to your computer and use it in GitHub Desktop.
Save brycejacobson/31096a6b8f3a96164a3c03bc62dd6e88 to your computer and use it in GitHub Desktop.
Get List of WordPress Custom Taxonomy Terms and Display Both Parent and Child
<?php
<ul class="vertical menu accordion-menu" data-accordion-menu>
<li>
<a href="#" class="accordion-menu__title">Categories</a>
<?php
$dinecategory = get_terms(
'dinecategory',
array(
'hide_empty' => 0,
'parent' => 0,
)
);
?>
<ul class="menu vertical nested is-active">
<h3>Categories</h3>
<?php
foreach ( $dinecategory as $dine_term ) :
?>
<li>
<label><input type="checkbox" name="listing-category" class="filter-term" data-filter-type="dinecategory" data-dinecategory-id="<?php echo $dine_term->term_id; ?>" data-term-id="<?php echo $dine_term->term_id; ?>" value="<?php echo $dine_term->slug; ?>"><?php echo $dine_term->name;?></label>
<?php
$dinecategory_subargs = array(
'hierarchical' => 1,
'show_option_none' => '',
'hide_empty' => 0,
'parent' => $dine_term->term_id,
'taxonomy' => array( 'dinecategory' ),
);
$dinecategory_child_categories = get_categories( $dinecategory_subargs );
if ( $dinecategory_child_categories ) {
?>
<ul class="is-active">
<?php
foreach ( $dinecategory_child_categories as $dinecategory_child_category ) :
?>
<li>
<label><input type="checkbox" name="listing-category" class="filter-term" data-filter-type="dinecategory" data-dinecategory-id="<?php echo $dinecategory_child_category->term_id; ?>" data-term-id="<?php echo $dinecategory_child_category->term_id; ?>" value="<?php echo $dinecategory_child_category->slug; ?>"><?php echo $dinecategory_child_category->name; ?></label>
</li>
<?php
endforeach;
?>
</ul>
<?php
}
?>
</li>
<?php
endforeach;
?>
</ul>
</li>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment