Last active
August 29, 2015 14:11
-
-
Save idenkov/3995f1e789c6f4bfb90f to your computer and use it in GitHub Desktop.
Get a dropown list of all the category names.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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