Created
January 27, 2012 17:59
-
-
Save wpsmith/1690040 to your computer and use it in GitHub Desktop.
CMB: Post Type Select
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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