Question:

Custom Post Type - Taxonomy Dropdown Menu?

Charlotte: 2 weeks ago

I have created a custom post type and added various meta boxes/fields to this custom post type. All is working excellent except for one element...

Instead of utilizing the default interface for selecting a taxonomy I would like to just have a drop down menu for the user to select from.

The idea here is to enable the admins to add taxonomy elements which can be managed centrally however for a specific post to only be associated with one taxonomy.

Further more, I would prefer to just add this drop down into one of my existing meta boxes.

Does anyone happen to have any sample code which would enable me to complete this task?

Answer:
Xavier: 2 weeks ago

This is how I did this.

<?php $tax = get_object_taxonomies('TAXONOMY_NAME');
    $taxterms = get_terms( $tax, 'orderby=count&offset=1&hide_empty=0&fields=all' );
?>
<select name='tax' id='tax'>
    <option value='' <?php if (!count( $names )) echo "selected";?>>Select Term</option>
    <?php 
    foreach ( $taxterms as $term ) { 
        echo '<option value="' . $term->slug . '" selected>' . $term->name . '</option>',"\n"; 
    } ?>
</select>