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
- Searching multiple custom post types and pages
- Return current page type
- Get page by template?
- Page as child in custom post type slug?
- 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?
- 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?
- 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?
- Check if admin is editing page or custom post type
- remove child post from custom post type archive
- 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
- 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
- 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
- Assign same parrent Page to pages AND custom post types
- 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
- How to use Custom Page Templates for hierarchical Custom Post Type
- Top Level pages in wordpress giving 404, but child pages working fine
- 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
- 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
- Page listing Custom Posts
- Display an authors post on a single page only when they are logged in
- Conflict between wp_list_pages and get_posts – list pages not displaying
- 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
- How to setup different permlalinks for posts and pages?
- Sets post_parent in custom post type posts automatically based on cpt->page name
- 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?
- 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?
- 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
- Disable Sidebar on certain pages
- Cannot save pages after migration
- Displaying posts inside table having issues
- Show posts from custom post type sorted by category/taxonomy on a one-pager/page
- Custom post types & Pages hierarchy – Error 404
- Wrap each child and it’s grandchildren separately
- How to manage a custom post type archive as a page?
- Creating Slider in wordpress theme with custom post
- How can I make my CPT read from page-*post-type*.php?
- One Post with different content, depending on a Page
- Cannot use pages created on WP
- Different post types arranged on one page
- Pulling Content from Existing Database
- Is it possible to make one of two custom fields in Custom Post Type UI Required but not the other?
- Excerpt for each post type and for is_front_page
- How to Associate Posts with Pages
- Include Custom Post Type Archive in wp_list_pages
- Programmatically Split A Post Into Multiple Pages
- Why are my wp urls showing page not found?
- query_post while (have post) get_template_part()?
- “regular” pages not found after changing permalink
- Display a custom post type list by taxonomy term
- Custom Post Type Slug / Page Slug Conflict – Prevent use of reserved slug on page save?
- Using custom post types within a section of a template
- current_page_item and custom post type?
- How to store queried custom data and use it in multiple pages?
- Highlight specific menu item when custom post is page
- How to add a regular page under a custom post type?
- An script/Plugin for automatic page creation per term