Skip to content

Instantly share code, notes, and snippets.

@idenkov
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idenkov/3995f1e789c6f4bfb90f to your computer and use it in GitHub Desktop.
Save idenkov/3995f1e789c6f4bfb90f to your computer and use it in GitHub Desktop.
Get a dropown list of all the category names.
<select name="event-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'>
<option value=""><?php echo esc_attr(__('Select Category')); ?></option>
<?php
$option = '<option value="' . get_option('home') . '/category/">All Categories</option>';
// change category to your custom page slug
$categories = get_terms( 'category', array(
'orderby' => 'count',
'hide_empty' => 0,
) );
foreach ($categories as $category) {
$option .= '<option value="'.get_option('home').'/category/'.$category->slug.'">';
$option .= $category->name;
$option .= ' ('.$category->count.')';
$option .= '</option>';
}
echo $option;
?>
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment