Skip to content

Instantly share code, notes, and snippets.

@wpsmith
Created January 20, 2012 14:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpsmith/1647598 to your computer and use it in GitHub Desktop.
Save wpsmith/1647598 to your computer and use it in GitHub Desktop.
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