Display Taxonomy Terms in an option tag with value being the slug

I have a custom taxonomy filled with terms that I wish to display in a fashion such as below.

<option value="[SLUG]">[TERM]</option>
<option value="[SLUG]">[TERM]</option>
<option value="[SLUG]">[TERM]</option>
...

I have attempted to use “wp_dropdown_categories” but I was unable to find a way to change the value=”[TERM_ID]” to value=”[SLUG]”

Read More

I also tried to use “wp_list_categories” and have it display with out the li’s hoping there was a tag like “wp_nav_menu” has with ‘before’=>”,’after’=>” but the documentation for “wp_list_categories” doesn’t seem to support that.

If you have any ideas on how to accomplish this it would be much appreciated.

Related posts

1 comment

  1. Use get_terms and output the term objects within whatever markup you need:

    $terms = get_terms( 'your-taxonomy' );
    
    if ( $terms ){
    
        echo '<select>';
    
        foreach ( $terms as $term ) {
            echo '<option value="' . $term->slug . '">' . $term->name . '</option>';
        }
    
        echo '</select>';
    
    }
    

Comments are closed.