Skip to content

Instantly share code, notes, and snippets.

@jbd91
Created January 15, 2021 20:39
Show Gist options
  • Save jbd91/92be05e789f7cf73cd6959ca83d99416 to your computer and use it in GitHub Desktop.
Save jbd91/92be05e789f7cf73cd6959ca83d99416 to your computer and use it in GitHub Desktop.
Hierarchial Mixitup Select Filter
<div class="filter-controls">
<div class="filter-controls__drop-down">
<select id="filterSelect">
<?php $hiterms = get_terms("dealer_locations", array("orderby" => "slug", "parent" => 0)); ?>
<?php foreach ($hiterms as $key => $hiterm) : ?>
<optgroup label="<?php echo $hiterm->name; ?>">
<?php $loterms = get_terms("dealer_locations", array("orderby" => "slug", "parent" => $hiterm->term_id)); ?>
<?php if ($loterms) : ?>
<?php foreach ($loterms as $key => $loterm) : ?>
<option data-filter=".<?php echo $loterm->slug; ?>"><?php echo $loterm->name; ?></option>
<?php endforeach; ?>
<?php endif; ?>
</optgroup>
<?php endforeach; ?>
</select>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment