Skip to content

Instantly share code, notes, and snippets.

@wpsmith wpsmith/gist:1647598
Created Jan 20, 2012

Embed
What would you like to do?
Expanding taxonomy_select
case 'taxonomy_select':
echo '<select name="', $field['id'], '" id="', $field['id'], '">';
$names= wp_get_object_terms( $post->ID, $field['taxonomy'] );
$terms = get_terms( $field['taxonomy'], 'hide_empty=0' );
if ( $field['options'] ) {
foreach ($field['options'] as $option) {
echo '<option value="', $option['value'], '"', $meta == $option['value'] ? ' selected="selected"' : '', '>', $option['name'], '</option>';
}
}
foreach ( $terms as $term ) {
if (!is_wp_error( $names ) && !empty( $names ) && !strcmp( $term->slug, $names[0]->slug ) ) {
echo '<option value="' . $term->slug . '" selected>' . $term->name . '</option>';
} else {
echo '<option value="' . $term->slug . ' ' , $meta == $term->slug ? $meta : ' ' ,' ">' . $term->name . '</option>';
}
}
echo '</select>';
echo '<p class="cmb_metabox_description">', $field['desc'], '</p>';
break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.