This code will return an array with IDs of all pages having sub pages. Hope you were looking for it 🙂
$args = array(
'post_type' => 'page',
'post_status' => 'publish'
);
$parentPages = array(); // an empty array to store pages with childs
$pages = get_pages($args);
// Looping through all pages and then we'll check for the pages with child
foreach($pages as $page) {
if($page->post_parent != 0){ // checking if the page has any parent
// checking if parent page isn't in our array already
if(!in_array($page->post_parent, $parentPages)) {
array_push($parentPages, $page->post_parent);
}
}
}
print_r($parentPages);
Related Posts:
- Global variable $post returning incorrect object
- Sending the reset password link programatically
- Getting only direct child pages in WordPress with get_pages
- Disable Attachment Pages Completely
- How to Remove all Instances of edit_post_link
- Any guides on creating custom admin pages?
- Multiple is_page() in page.php
- Create WordPress pages with PHP
- Is it possible to generate a page without create in the admin?
- WordPress admin never finishes saving page on site with large page count
- Archive listing of posts by publish year (multiple years)
- add_rewrite_rule with bottom priority doesn’t handle the WordPress pages
- Listing all sub-pages?
- Help with a custom page template – listing contents of childpages?
- Print number of post (in reverse)
- Archive dropdown styling not applied
- Passing the page ID to a login php script
- Use is_product_category() properly
- How can the plugin directory path be returned into ?
- Add a Different CSS Class Into The Body Tag of Different WP Pages
- syntax issue on php 7.4
- Custom Template 404 for specific custom post type
- Can’t load WP function into external function
- How to query for pages/post depending on slug?
- Way to querry data (tags) from a wordpress database?
- Show full posts in archive
- How to add a php custom page to WordPress
- My page.php shows the index.php
- How can I add an area/option for a custom page description?
- Create Page To Count Comments For Each Post In WordPress Site
- wordpress archive a user
- get_the_title() gets printed out twice
- How do I find PHP file that contains content of my page?
- WordPress page content outside WordPress
- Inject class in body when particular page template is used
- Use .php file as page instead of wordpress page & template file?
- Use WordPress function in php file
- How to check if the current page is at a specified path in the URL?
- Show About and Contact Us page when they’re clicked in the top menu.
- Parsing Menu Items and Blog Posts
- How do I remove a category from a wordpress loop>
- What’s the best way to include PHP code in pages?
- Automatically add images to a menu
- page-slug.php not working but only for specific slug
- Need php code’s output to display underneath a Divi Module
- Issue with custom loop in Archive page
- How to echo every parent page title?
- How Do I Find & Remove H1 From Site-Title-Wrapper? [closed]
- Retrieve Json data and create multiple pages with it
- Display child page content of a specific parent on home page
- Removing custom sort order from admin page listing
- PHP Output also in Child theme, but different
- $wpdb->get_results breaking page?
- Unique PHP on each Page
- How to Display a List of Child Pages For a Parent Page in WordPress
- If is page, archive or search output this code
- WordPress Search
- List all anchor links on a page
- First post article different on Archives template
- How do I add my PHP app to a WordPress page whilst keeping semantic URLs?
- Page load timer?
- Page not visible in ‘All pages’ after being added through PHP
- Cascading dropdown select search based on Parent Page & Child Page
- Edit and delete permissions pages and posts
- My worpress search page is showing no results
- A function to get the content of a page
- Displaying the Archive Page’s Name on the Page
- How can I check if a post with a particular slug or title exists?
- Display WordPress archive template page in 3 columns and not 1 column [closed]
- When I click for the redirect link it is showing the content of index.php instead of single_assignment_page.php
- Category Page Displaying all Pages
- Exclude category from function – PHP
- Display page content in different sections – based on page break block?
- Do not show child pages within a file page
- Child and Parent Pages list of sub pages
- loading a php file to a specific page id
- Use page-templates without creating theme
- Get current_post in reverse order with pagination
- How to add custom text near category/tag title in WordPress Twenty Fifteen Theme?
- Newbie question. Login/Registration. New PHP page
- Adding my own custom template page but got white page
- Create a custom theme-specific page, invisible in the admin-panel?
- Archive page if else not working for post_excerpt and post_content
- Execute php in pages
- Page 2+ of taxonomy archives does not recognise sort-order from dropdown
- Why isn’t my link attribute getting my css?
- How to map my php files as the files for pages
- Show results for multiple page-types
- How to add feature image url in my template file and content as well?
- Display selected parts from selected pages on the frontpage?
- dynamically filter by category via sub-menu
- Adding Media button to only pages
- I want Page titles and excerpts to show up on home.php in certain order
- Custom Archive Page
- ACF: Echo page title when checkbox is checked
- How to refresh a template page on WordPress in 3 seconds – easiest method?
- archive per year with monthly
- Custom archives page by month and year – nesting problem
- How to handle parent and child pages?
- How do I remove blog entries from home page Twenty Eleven child theme?