I am using wp_dropdown_pages
in the backend of my site to generate a list of pages according to a specific set of criteria.
The list only shows published posts where I would like it to show both published posts and drafts.
I have found other Stack Exchange threads which show how to accomplish this in the standard wordpress dropdowns, but this does not seem to extend to wp_dropdown_pages
.
What I am using to show drafts in the standard dropdowns is this:
<?php
/* Show drafts in dropdown lists */
add_filter('page_attributes_dropdown_pages_args', 'my_attributes_dropdown_pages_args', 1, 1);
add_filter('quick_edit_dropdown_pages_args', 'my_attributes_dropdown_pages_args', 1, 1);
function my_attributes_dropdown_pages_args($dropdown_args) {
$dropdown_args['post_status'] = array('publish','draft');
return $dropdown_args;
}
?>
The above works great. I would like to do exactly the same thing for custom fields generated using wp_dropdown_pages
. To clarify, in the backend, I am generating a dropdown list using the following code:
<?php
$dropdown_args_food = array(
'depth' => '2',
'selected' => $selectedFoodType,
'post_type' => 'page',
'name' => 'selected-food-type',
'id' => 'selected-food-type',
'echo' => 1,
'meta_key' => 'category',
'meta_value' => 'food',
'hierarchical' => 1,
'show_option_none' => ' ',
);
wp_dropdown_pages( $dropdown_args_food );
?>
The above generates a dropdown list of pages exactly as I want it to be, only without drafts.