Created
July 28, 2012 22:58
-
-
Save abachuk/3195113 to your computer and use it in GitHub Desktop.
Custom Post type meta box for WordPress (extension to CPT)
This file contains hidden or 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
/******* RELATED PAGES METABOX *********/ | |
add_action( 'cmb_render_select_post', 'rrh_cmb_render_select_post', 10, 2 ); | |
function rrh_cmb_render_select_post( $field, $meta ) { | |
global $posts; | |
$posts = get_posts( array( 'post_type' => 'page', 'posts_per_page' => -1 )); | |
echo '<select name="', $field['id'], '" id="', $field['id'], '">'; | |
foreach ($posts as $option) { | |
echo '<option value="', $option->ID, '"', $meta == $option->ID ? ' selected="selected"' : '', '>', $option->post_title, '</option>'; | |
} | |
echo '</select>'; | |
echo '<p class="cmb_metabox_description">', $field['desc'], '</p>'; | |
} | |
$meta_boxes[] = array( | |
'id' => 'related_pages', | |
'title' => 'Related Pages', | |
'pages' => array('page'), // post type | |
'context' => 'normal', | |
'priority' => 'high', | |
'show_names' => true, // Show field names on the left | |
'fields' => array( | |
array( | |
'name' => 'Previous Page', | |
'desc' => '', | |
'id' => $prefix . 'prev_page', | |
'type' => 'select_post', | |
), | |
array( | |
'name' => 'Next Page', | |
'desc' => '', | |
'id' => $prefix . 'next_page', | |
'type' => 'select_post', | |
), | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment