How can I show drafts in wp_dropdown_pages list?

Update

It seems that you can do this directly with WP function wp_dropdown_pages() as birgire points out in his response below:
https://wordpress.stackexchange.com/a/240275/102371


This solution is longer, and uses get_posts() to fetch specific post statuses.

$pages = get_posts( array( 'post_type' => 'page', 'post_parent' => 0, 'post_status' => array( 'draft', 'publish' ) ) );

echo '<select name="selected-food-type" id="selected-food-type">';
foreach( $pages as $page ) {
    echo '<option value="' . $page->ID . '">' . get_the_title( $page->ID ) . '</option>';
    $children = get_children( 'post_parent=". $page->ID );
    foreach( $children as $subpage ) {
        echo "<option value="' . $subpage->ID . '">&nbsp;&nbsp;&nbsp;' . get_the_title( $subpage->ID ) . '</option>';
    }
}
echo '</select>';

Leave a Comment