The problem is here
$subpages = get_pages( array(
'child_of' => $pageId,
'sort_order' => 'asc',
'sort_column' => 'menu_order') );
‘child_of’ parameter also queries for the grandchildren along with children. Use the ‘parent’ parameter instead which will only query for the direct children. Once this is done, you’ll use the same code in your foreach again
foreach($subpages as $page) {
$subsubpages = get_pages( array(
'parent' => $page->ID,
'sort_order' => 'asc',
'sort_column' => 'menu_order') );
// use $subsubpages along with $page here
}
If you want to go even lower in levels, you will probably want to implement this logic in the form of a recursive function
Related Posts:
- Is there a way to make a custom Page type?
- Custom Post Type Name Causing Problem
- How to display data with pagaination on backend?
- Hook for post and page load
- Integrating a custom post type into a page hierarchy
- Custom Post Type Slug / Page Slug Conflict – Prevent use of reserved slug on page save?
- Searching multiple custom post types and pages
- Return current page type
- Custom Post Type as Page parent
- How to add a post from a custom post type as the static page?
- Get page by template?
- Page as child in custom post type slug?
- Highlighting current item of custom post types’ sub pages, listed by wp_list_pages
- Is it proper to create a page just to generate a listing page (eg. for a custom post type)
- TV Show database – Best way for structuring it?
- Menu position (admin menu) of pages
- How to Add Pages Under Custom Post Type URL Structure?
- Custom Posts on Different Pages
- Pagination with custom loop
- Include images from pages in wp search.php results in default wp search
- Priority for Categories, Tags, Taxonomies, Posts, Pages and Custom Posts with same url
- How to create user personal pages with information from their meta profile fields?
- Exclude Custom Post Type & Pages From Auto-Tag Function
- Display “Post 2 of 4” on single post page?
- Make custom post type display as a page
- wp_list_pages doesn’t work in hierarchical custom post type
- Multiple portfolios with one custom post type?
- Is it possible to use pages to apply static content to each taxonomy level?
- Making pages also serve as taxonomies? Or give full pages to taxonomies?
- Share parent path between Custom Post Types and Pages?
- ‘Pages’ widget alternative for custom post types?
- Custom Blog Post Listing in Genesis Sample Child Theme
- Hierarchical Custom Posts – Highlighting Current Post in Sub-Menu
- Check if admin is editing page or custom post type
- remove child post from custom post type archive
- Pull in custom content types into page template
- custom posts on different page
- wp_list_pages(); Change output of hyperlink
- Trying to edit the single page from a Custom Post
- How do I fix permalinks for custom post types that has the same slug as a page?
- Create custom PAGE with register_post_type
- Should I use custom taxonomy or custom post type
- Disable featured image
- Making a custom help center page
- How i can add ‘N’ page of ‘N’ pages under posts loop?
- create a template page for a post
- Page vs Custom Post Types Differences/Issues
- Allow non-logged in users to see a future post after clicking on a list of future posts
- wordpress wp_list_pages help
- Exclude pages in archives results
- Make parts of your wordpress website completely built with data from external APIs?
- Trouble with CPT Child 404
- Database to page routing API?
- Assign same parrent Page to pages AND custom post types
- Allow Static Page Load Dynamic Child Pages
- No Permission to add new Page, Post or CPT with Admin role
- Static page determines as home, but it is not
- Show Custom Post Type meta boxes only on Page Edit
- Why does my content disapear when I make a page to match an archive name?
- How to use Custom Page Templates for hierarchical Custom Post Type
- Top Level pages in wordpress giving 404, but child pages working fine
- Page for custom post type
- Why does not this wp_redirect work in is_single()?
- Why is get_pages() returning a boolean?
- Pros and cons of a custom page vs custom post type template file
- How to include custom post type posts on a page?
- Including link to custom post type in ‘wp_list_pages’ function
- the_content(); of custom post type treated as an array or object
- Multiple pages per post (not pagination)
- Display custom post types in wp_list_pages
- Can I change my post type to anything and my site still work?
- Page listing Custom Posts
- Display an authors post on a single page only when they are logged in
- Why are some of my custom posts not showing up on my page?
- Merge page with custom post type
- Conflict between wp_list_pages and get_posts – list pages not displaying
- Hide Status Option From WordPress Publish Metabox and Rename Published on:
- URL Rewrite – Page Archive
- How to set the mainpage of a custom post type?
- Render a Post or Page using the correct file
- Setting a homepage – doesn’t seem to work
- Under What Conditions Can I name my CPT the same as my CPT Page?
- custom post creation on front page – on submit a search is done
- wp_dropdown_pages with tax_query clause
- Am I mixing up the concept of posts pages and categories?
- How to setup different permlalinks for posts and pages?
- Sets post_parent in custom post type posts automatically based on cpt->page name
- Tag template not returning posts [closed]
- Does “Custom Post Type” can have page hierarhy option?
- How do I disable the built-in editor and automatically configure the properties of new pages?
- How to set a ‘page’ as parent of a custom post type?
- Manually adding current_page_parent to wp_list_pages()
- build child and anchestor three from post parent
- Add custom template ‘sub-page’ to Custom Post type?
- Metabox collapsed by default
- How to use posts as tabs in a custom page?
- Custom Post Type Single Page and Archive Page redirects to Home Page
- Create Custom page with custom domain
- How to stop a permalink redirecting to a page whit same slug but different permalink
- Do not show child pages within a file page