WordPress wp_dropdown_categories for Custom Taxonomies with No Submit Button

I went searching for how to customize WordPress’ wp_dropdown_categories for custom taxonomies today, and to implement it in a way that didn’t require a submit button. While WordPress added a taxonomy parameter for the function, it doesn’t work with the default Javascript outlined on the Codex page as it returns the ID of the taxonomy term, not the slug, and for whatever reason, http://website.com/?taxonomy=5 doesn’t automatically forward to http://website.com//taxonomy-slug/term-slug/.

Using some code cobbled together via scraps of incomplete code from Frankie Jarrett, a commenter on his site and the Javascript that works with the select value changing from the form itself, I’ve figured this out and am happy to provide it to anyone else interested.

Add this function to your functions.php file:

function click_taxonomy_dropdown($taxonomy) { ?>
<form action="/" method="get">
<select name="cat" id="cat" class="postform">
<option value="-1">Choose one...</option>
<?php
$terms = get_terms($taxonomy);
foreach ($terms as $term) {
printf( '<option class="level-0" value="%s">%s</option>', $term->slug, $term->name );
}
echo '</select></form>';
?>
<?php }

And then this to your site’s theme, replacing TAXONOMY with your taxonomies slug:

<?php click_taxonomy_dropdown( 'collection' ); ?>
<script type="text/javascript"><!--
var dropdown = document.getElementById("cat");
function onCatChange() {
if ( dropdown.options[dropdown.selectedIndex].value > '' ) {
location.href = "<?php echo get_option('home'); ?>/?TAXONOMY="+dropdown.options[dropdown.selectedIndex].value;
}
}
dropdown.onchange = onCatChange;
--></script>

Up Next: How to Get WordPress Working with SVG Files