Skip to content

Instantly share code, notes, and snippets.

@wpsmith
Created January 27, 2012 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpsmith/1690040 to your computer and use it in GitHub Desktop.
Save wpsmith/1690040 to your computer and use it in GitHub Desktop.
CMB: Post Type Select
add_action( 'ntg_render_post_type_select' , 'wps_post_type_select' , 10 , 3 );
function wps_post_type_select ( $field, $meta, $id ) {
global $post;
if ( $field['type'] == 'post_type_select' ) {
echo '<select name="', $id, '" id="', $id, '">';
$pts = get_post_types();
if ( $field['options'] ) {
foreach ($field['options'] as $option) {
echo '<option value="', $option['value'], '"', $meta == $option['value'] ? ' selected="selected"' : '', '>', $option['name'], '</option>';
}
}
foreach ( get_post_types( $field['post_type_args'], 'objects' ) as $pt ) {
echo '<option value="' . $pt->name . '" ' , selected ( $meta , $pt->name ) ,'>' . $pt->labels->name . '</option>';
}
echo '</select>';
echo '<p class="cmb_metabox_description">', $field['desc'], '</p>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment