Skip to content

Instantly share code, notes, and snippets.

@wpsmith
Created June 1, 2012 18:42
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 wpsmith/2854297 to your computer and use it in GitHub Desktop.
Save wpsmith/2854297 to your computer and use it in GitHub Desktop.
Taxonomy Dropdown
<?php
/**
* Creates HTML markup for taxonomy dropdown
*
* @param string $taxonomy Registered taxonomy name
*/
function we_tax_dropdown( $taxonomy ) {
$terms = get_terms( $taxonomy );
$taxonomy = get_taxonomy( $taxonomy );
if ( empty( $terms ) )
return;
$current = get_query_var( $taxonomy->name );
echo "<select name='$taxonomy->name' id='$taxonomy->name' class='taxonomy-search postform'>\n\t";
echo '<option value="" ' . selected( $current == '', true, false ) . '>' . __( 'Select ' . $taxonomy->labels->name, CHILD_DOMAIN ) . '</option>';
foreach ( (array) $terms as $term )
echo "\t<option value='{$term->slug}' " . selected( $current, $term->slug, false ) . ">{$term->name} ({$term->count})</option>\n";
echo '</select>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment