Skip to content

Instantly share code, notes, and snippets.

@wpsmith wpsmith/gist:1690040
Created Jan 27, 2012

Embed
What would you like to do?
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
You can’t perform that action at this time.