Update 3.0.3+ shoots wp_dropdown_pages
-
Update 3.0.2 it works fine, since Update 3.0.3. you shoot wp_dropdown_pages.
Example: you have a custom-post-type (hirarchhical yes, like pages). Then you add a MetaBox to posts, where you can select this custom-post-type (with wp_dropdown_pages).
Like this:wp_dropdown_pages(array( 'post_type' => 'customposttype', 'id' => 'Test', ));
So with Update 3.0.2. everything works fine. Since Update 3.0.3 (all later updates tried), the dropdown do not work anymore. I have created a quick-and-dirty plugin to test it. This creates a custom-post-type and a select field in posts:
class Custom_Meta_Box { public function __construct() { if ( is_admin() ) { add_action( 'load-post.php', array( $this, 'init_metabox' ) ); add_action( 'load-post-new.php', array( $this, 'init_metabox' ) ); } } public function init_metabox() { add_action( 'add_meta_boxes', array( $this, 'add_metabox' ) ); add_action( 'save_post', array( $this, 'save_metabox' ), 10, 2 ); } public function add_metabox() { add_meta_box( 'test', 'Test', array( $this, 'render_metabox' ), 'post', 'advanced', 'default' ); } public function render_metabox( $post ) { // Retrieve an existing value from the database. $custom_testid = get_post_meta( $post->ID, 'custom_testid', true ); // Set default values. if( empty( $custom_testid ) ) $custom_testid = ''; // Form fields. echo '<table class="form-table">'; echo ' <tr>'; echo ' <th><label for="custom_testid" class="custom_testid_label">' . 'Test field' . '</label></th>'; echo ' <td>'; wp_dropdown_pages( array( 'id' => 'custom_testid', 'name' => 'custom_testid', 'class' => 'custom_testid_field', 'selected' => $custom_testid, 'post_type' => 'test' ,'show_option_none' => '--Please select--', 'option_none_value' => 0) ); echo ' </td>'; echo ' </tr>'; echo '</table>'; } public function save_metabox( $post_id, $post ) { // Sanitize user input. $custom_new_testid = isset( $_POST[ 'custom_testid' ] ) ? sanitize_text_field( $_POST[ 'custom_testid' ] ) : ''; // Update the meta field in the database. update_post_meta( $post_id, 'custom_testid', $custom_new_testid ); } } new Custom_Meta_Box; // Register Custom Post Type function xyz_custom_post_type() { $labels = array( 'menu_name' => 'Test Post Type', ); $args = array( 'label' => 'Post Type', 'description' => 'TEST', 'labels' => $labels, 'supports' => array( 'title', 'editor' ), 'hierarchical' => true, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 5, 'show_in_admin_bar' => true, 'show_in_nav_menus' => true, 'can_export' => true, 'has_archive' => true, 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => 'page', ); register_post_type( 'test', $args ); } add_action( 'init', 'xyz_custom_post_type', 0 );
With this plugin, you create a new Test Post Type. With Update 3.0.2. you see on Post screen a select with the Test-Post-Type. With Update 3.0.3+ you see the select label, but no select field.
- The topic ‘Update 3.0.3+ shoots wp_dropdown_pages’ is closed to new replies.