• Resolved wp-patrick

    (@wp-patrick)


    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.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Kyle Phillips

    (@kylephillips)

    I’ve tested your plugin code above with Nested Pages v3.0.5, and the page dropdown is working as expected.

    There was a bug in 3.0.3 that was patched in 3.0.4. If you haven’t updated to the latest version I would recommend that.

    May be unrelated to your production code, but the meta box in the above code is registered for the “post” post type rather than the “test” post type.

    Thread Starter wp-patrick

    (@wp-patrick)

    I have testet with version 3.0.4 till 3.0.5, the above code was not working. The Meta box is exactly the problem. On “post” post type there is the meta box with wp_dropdown_pages functions where takes the “test” post type posts. In other words; on a “post” I have to select a “test”.
    Did you have tested exactly this? Because the dropdown with type “page” was working, just with “test” it was not working.

    I have the same problem. Since 3.0.3, Nested Pages added a hook on “wp_dropdown_pages” wich is causing few problems.
    In my case, the plugin “Multisite Language Switcher” is listing pages with “wp_dropdown_pages” functions and due to Nested Pages update, the page list is returned with no arguments (most importantly the “name” parameter is lost).
    Had to downgrade to 3.0.2.

    Plugin Author Kyle Phillips

    (@kylephillips)

    I understand now. This should be fixed in v3.0.6, just released.

    Works fine now with v3.0.6, thanks !

    Thread Starter wp-patrick

    (@wp-patrick)

    Okay, works for me too with 3.0.6, thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Update 3.0.3+ shoots wp_dropdown_pages’ is closed to new replies.