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
- Only get_posts of certain post formats
- Disable Attachment Pages Completely
- How to add a .php file to WordPress
- How to Remove all Instances of edit_post_link
- Any guides on creating custom admin pages?
- Multiple is_page() in page.php
- How to check if feed URL was requested?
- Create WordPress pages with PHP
- Is it possible to generate a page without create in the admin?
- How to change “Shipping Calculator “field label on Cart Page – woocommerce? [closed]
- WordPress admin never finishes saving page on site with large page count
- class=”parent” for wp_list_pages?
- Archive listing of posts by publish year (multiple years)
- PHP Script within wordpress theme
- add_rewrite_rule with bottom priority doesn’t handle the WordPress pages
- Listing all sub-pages?
- How to link to a custom .php page in my folder
- Get only the grandchildren, not the direct children of page/current page?
- 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
- Limit get_pages to only show 5 items
- syntax issue on php 7.4
- How do I publish only one page to production after making changes on staging?
- Custom Template 404 for specific custom post type
- Can’t load WP function into external function
- Custom category code not showing all posts
- How to query for pages/post depending on slug?
- Insert a button on a page with random number generation
- Can’t get page content in WordPress
- Way to querry data (tags) from a wordpress database?
- How can I load a PHP page without using a Template?
- Best practice for migration friendly images in posts/pages?
- Show full posts in archive
- Getting the author name on author archive page
- Page Automatically Generated from Theme?
- How to add a php custom page to WordPress
- Sort query_posts for Parent Pages to menue order or the count?
- How to hide all child pages with post_query?
- What is an equivalent of single_cat_title for getting the slug of the category?
- My page.php shows the index.php
- Populate editor with some content of a page with a page template
- 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
- Using the_excerpt() on a page
- 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
- Why am I getting a different filename? And how does WordPress load singular.php for both Page & Post? (Fresh WordPress installation)
- 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 to use theme function in post/page?
- My php code is not being executed
- Using Shortcode to Grab Archive Listing, Separate by Year
- How do I remove a category from a wordpress loop>
- trouble with page_id & highlighting current page
- Apply class to every third list item? [duplicate]
- How to include custom code on a page that’s set to act as homepage?
- Can a page contain php code?
- 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
- Insert page content into another page with a changed variable
- 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
- How to add page numbering with php?
- Display child page content of a specific parent on home page
- Noindex subscriber author 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
- How to Fix an Archive.php That Displays All Posts?
- List all anchor links on a page
- First post article different on Archives template
- Toolbar Hidden in a Virtual Page
- How do I add my PHP app to a WordPress page whilst keeping semantic URLs?
- Page load timer?
- Blog suddenly shows Archive instead of index page
- Page not visible in ‘All pages’ after being added through PHP
- Woocommerce. Get a list of products in the current category on the archive page and product page
- Cascading dropdown select search based on Parent Page & Child Page