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]
- How to only hook on Single.php after content?
- What characters are allowed as a shortcode tag and how should they be sanitized?
- How to remove filter added by another plugin in a class
- Best way to manage a lot of pages in Wp Admin [closed]
- Using add_filter inside another class
- Pages with 2 Columns
- Add custom meta box on Post page
- Hide WordPress Plugin Deactivation Links
- Alter post slug by a filter that is fired just after a post is created
- how to display all posts Custom fields dynamically?
- Pass A Value From Outside To A Plugin Variable
- Does the ‘nav_menu_css_class’ filter accept 2 or 3 arguments?
- do_action and hook methods
- ElasticPress how to Include Meta to the mapping?
- How to show category images (from plugin) on a regular page (page-example.php)?
- How to create Repeater fields using Advanced Custom Fields?
- [Plugin: Posts 2 Posts] How does it work?
- Reposition Woocommerce Message
- Add a plugin before main container
- WordPress CMB2 – Run function on save
- How to modify shortcode attributes with data from current post
- Can I hook into get_avatar to supply a hash instead of an email?
- How do action and filter hooks understand where to look for the core function that we hooked our function to them
- Carbon Fields use in custom plugin class
- How to query the custom fields by language?
- Modifying the comments section through a plugin regardless of theme
- Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
- Passing an array from shortcode-function to filter-function
- Get Time Taken By Each Action Hook in WordPress
- WordPress page and plugin list using sql query
- 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
- Using add_action before add_filter on a plugin?
- How to have sample page for each new register users in a membership website
- remove_action not removing add_action from constructor
- How to Resize the Custom Post Images?
- Simulating a wp page – wp page load sequence
- Add a function call after content automatically?
- Custom form not showing in correct place on page
- How to use add_action for multiple instances of the same class
- Use jQuery Datepicker code from plugin
- How to Use the Filter “sidebar_login_widget_form_args”
- is there a way to pass a parameter to a add_menu_page function?
- How to force load a page in plugin?
- Dropdown menu on click change
- Plugin that lets visitors Like a post (not facebook) and stores likes in custom meta?
- Adding a pagenavi to function for displaying bookmarks
- grab or load text on demand
- Dictionary-style definition list plugin
- Is there a syntax highlighting plugin for HTML View? [duplicate]
- Edit post image attributes on fly?
- How to permanently show Word Counter on Create/Edit Page. WordPress5.9.3
- Add hook after content without formatting
- Copy/paste local images not working in WordPress
- get_post_meta shortcode returns empty field
- Adding an item to an anonymous array inside a filter?
- $wpdb not working wordpress plugin ajax call
- Adding Custom Endpoint in WordPress Rest API
- General Term for this form Field
- Load google font script based on optgroup label selected
- How do I change the functionality of an image slider which is part of ACF?
- Make custom post types using ACF
- How to allow URL with filename & extension in wordpress?
- How to pass multiple custom fields as shortcode’s parameters
- Modify function output in a plugin
- Override filter variable not working
- Taxonomy question
- Help needed with woocommerce (wc stripe) filter
- How to remove a css class for any wordpress page
- show-hide based on select option jquery wordpress
- Add custom field for users
- Options page textarea to populate custom post select field
- Creating a user ‘add custom field’ section
- Better code/text editing for posts and pages?
- passing ‘&’ in return function of add_filter
- Filter for modifying image on upload
- Fake Single WordPress Post (Page) Loop
- How to set different users for different pages?
- Strip shortcode from excerpt [duplicate]
- force category table refresh when adding new category
- County Finder form/plugin?
- add query string to all pages after user logged in
- get_post_meta does not work
- ACF: Hide a div or template section when a custom field (in a field group) is empty
- How ACF Advanced Custom Field works with Woocommerce Single Product [closed]
- Displaying Random Image from ACF Options Page [closed]
- Need help saving input fields for Security Deposit plugin in WC Vendors page
- Adding a variable to a meta field in the backend?
- ACF: Not displaying ACF data from another post
- How to add product thumbnail on orders list on backend?
- Set the Social Icon Size in footer