Taxonomy category dropdown
Categoria:
Wordpress, hooksSnippet:
<?php
if( $terms = get_terms( array(
'taxonomy' => 'category', // to make it simple I use default categories
'orderby' => 'name'
) ) ) :
// if categories exist, display the dropdown
echo '<select name="categoryfilter"><option value="">Select category...</option>';
foreach ( $terms as $term ) :
echo '<option value="' . $term->term_id . '">' . $term->name . '</option>'; // ID of the category as an option value
endforeach;
echo '</select>';
endif;
Versiones:
Descripción:
Genera un desplegable con la taxonomía designada. Por defecto, la categoría. Pero también funcionaría con "tags", "proyectos", "custom_taxonomy"