Automatically generate a list of all published pages for a metabox select field. This meta box would allow a wordpress user to select a page to associate with another page or post.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
/* ADD PAGE SELECT FIELD */ function metabox_page_select_field( $field, $meta ) { $args = array( 'depth' => 0, 'child_of' => 0, 'selected' => $meta, 'echo' => 1, 'name' => $field['id'] ); wp_dropdown_pages($args); echo '<p class="cmb_metabox_description">', $field['desc'], '</p>'; }//end metabox_page_select_field add_action( 'cmb_render_page_select', 'metabox_page_select_field', 10, 2 ); function metabox_page_select_field_validate( $new ) { if ( !is_numeric( $new ) ) {$new = "";} return $new; }//end metabox_page_select_field_validate add_filter( 'cmb_validate_page_select', 'metabox_page_select_field_validate' ); |
A great plugin for custom metaboxes … Continued