Skip to content

Instantly share code, notes, and snippets.

@zartgesotten
Last active October 24, 2017 09:01
Show Gist options
  • Save zartgesotten/190fc9487b828c114820a7815a540a78 to your computer and use it in GitHub Desktop.
Save zartgesotten/190fc9487b828c114820a7815a540a78 to your computer and use it in GitHub Desktop.
Creates a dropdown with all event categories Has to be added to template where the dropdown should be displayed. Sources: https://theeventscalendar.com/support/forums/topic/category-dropdown/ https://pastebin.com/jg2hr5yz
<?php
$categories = get_categories(
array(
'taxonomy' => TribeEvents::TAXONOMY,
'selected' => 0,
'orderby' => 'name'
) );
?>
<script type="text/javascript"><!--
function onCatChange(select) {
var slug = select.options[select.selectedIndex].value;
var link = '<?= tribe_get_events_link() ?>';
location.href = (slug == 'all') ? link : link + 'category/' + slug;
}
--></script>
<select id="categories" onchange="onCatChange(this)" >
<option value="all">All Events</option>
<?php
foreach ($categories as $cat) {
if (tribe_meta_event_category_name() == $cat->name) $selected='selected';
else $selected = '';
?>
<option value="<?= $cat->slug ?>" <?= $selected ?>><?= $cat->name ?></option>
<?php } ?>
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment