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 . '"> ' . get_the_title( $subpage->ID ) . '</option>';
}
}
echo '</select>';
Related Posts:
- add_meta_box Callback not being called
- Proper way to replace the_content only for pages created by custom plugin
- Redirect to another page using contact form 7? [closed]
- Price comparison table based on Custom Post Type?
- Elementor: How to design Dropdown Select Box Navigation page like Chegg
- Randomize post (and page) IDs on generation
- How do I add custom fields to the “Edit page” admin screen?
- Order shipped by which driver[hook for woocoomerce order staus changed and popup in admin panel ] [closed]
- Carbon Fields use in custom plugin class
- View Private Published Page with URL Code (no login required)
- How I can get custom field’s current value?
- UnWanted Custom field added in the wp page edit area
- Do action only on certain front end pages?
- Woocommerce – How to populate custom select field with stored values on checkout page?
- How to append to title via functions.php for auto-posting plugin [duplicate]
- Implement Autocomplete for a custom field on WordPress Plugin Frontend
- How to query the custom fields by language?
- Edit default comments page in WP Admin
- Inserting above the comment template
- Creating a plugin to sanitize comment and the url field before display only
- How to find the origin of a file upload from within wp_handle_upload?
- Modifying the comments section through a plugin regardless of theme
- Easiest way to add dropdown to a page
- Assign / update custom field value for all posts (How can I assign only to posts without custom field value?)
- How to get the element ID from new menu list that added with add_filter()?
- page_attributes_dropdown_pages_args filter does not work
- How to delete page by deactivating plugin
- Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
- WordPress web pages keep getting deleted (moved into the trash) by themselves
- White page by using filter template_include
- Run plugins only on certain pages
- How to check current user before all actions and filters?
- How do I create a filter feature on WordPress? [closed]
- (FES EDD) New vendor submission page is blank
- Create a navbar filter that filters by a custom field
- auto populate list of questions if user select a category xyz
- is there a way to link one of the field in ACF field group, to a field in a media attachment page? [closed]
- How to toggle between two custom fields in WordPress woocommerce ‘WC Product Field Group’ plugin?
- Passing an array from shortcode-function to filter-function
- Get Time Taken By Each Action Hook in WordPress
- How to create an input field, and base the output on spreadsheet data? [closed]
- I want to auto populate data in three fields if one drop down is selected
- Filtering WooCommerce Orders by Category
- How to remove plugin metaboxes from edit.php
- WordPress plugin/theme or other wayout to create portable pages?
- How do I hide posts across all loops based on the value of a custom field?
- Plugin developer automated documentation
- php page not found for plugin options menu
- qTranslate remove default directory from link
- How to disable a plugin for certain page?
- Output content to the_content before a plugin does
- Is there a hook to Intercept al urls from a webpage and redirect to a page
- Changing page URL and connect newsletter to MailChip
- WordPress user account activation
- Custom User meta field display
- WordPress page and plugin list using sql query
- Create page from plugin, but have it completely hidden
- External Script Using WP – Hooks / Actions Not Working?
- URL parameters causing 404 on home page, but nowhere else
- Which filter affects the ‘entry-title’ post class
- How to change the name of the “edit my profile” link in the WordPress admin backend
- Filtering get_permalink in Jetpack / ShareDaddy
- Execute js files doesn’t seem to work
- How to add subcategories to the blogroll?
- WordPress metaboxes – textfield suggestion automatically populated
- Char limit on custom blog-post form? [closed]
- How do I write an inventory list plugin that creates dynamic details pages?
- Can I allow certain people to add/edit pages within a parent?
- Unable to select image using custom image field type
- add_filter doesn’t work
- Add menu page issues (permissions & position)
- Every new post/draft has a custom field variable “yst_is_cornerstone” showing
- Template filter for custom taxonomy terms
- Display Custom Field Value on Admin Page Column
- Is there a way to figure out which action/filter invoked a function?
- Would Gutenberg be considered a PlugIn?
- I need help locating a URL that is on my site map, but that I can’t find in my WordPress dashboard
- Show author on every sub-page
- Add sub menu page in your plugin
- Custom Post Type Fields
- How do I enforce users to fill a determined custom field using WyPiekacz?
- Using add_action before add_filter on a plugin?
- Check if variable is set in filter
- What exactly happens to function argument availability when using a filter?
- How to have sample page for each new register users in a membership website
- Passing stored variables to add_filter
- Modify page title and subtitle with a plugin
- One sub site is slow while all others load fine, same theme & plugins [closed]
- override filter in a plugin
- Check filter defined or not?
- remove_action not removing add_action from constructor
- How to create a page with links to other pages that include image and excerpt?
- How can I apply a WP filter on specific plugin version
- Thesis 2 custom Page
- Adding class to last list item? Not WP generated
- Making my plugin create a page?
- Add Content to Content()
- How to Resize the Custom Post Images?
- Editing wp-config.php
- Amazon.com intergration with WordPress?