Use ancestors:
$ancestors = array_reverse( get_post_ancestors( $post->ID ) ); // reverse ancestors to make it more intuitive
if ( isset( $ancestors[0] ) ) {
if ( isset( $ancestors[1] ) ) {
// 3rd tier
$parent_id = $post->post_parent;
} else {
// 2nd tier
$parent_id = $post->ID;
}
$args = array(
'depth' => 1,
'child_of' => $parent_id,
);
wp_list_pages( $args );
}
Related Posts:
- How can I include ALL post types in the_post_navigation() links, not just current post type?
- Exclude certain template from wp_list_pages
- Get name of the current template file
- How do you find out which template page is serving the current page?
- Adding Page Attributes Metabox and Page Templates to the Posts Edit Page?
- Is there a way to list all used/unused WP templates?
- Print WordPress template filename(s) for debugging
- Change the name of the ‘Default Template’
- Echoing Elementor page content in template, but it doesn’t get styles and some widgets are missing
- How can I modify the default reset (lost) password email text?
- Template files missing after moving site
- Create Page that uses specific template
- Sharing templates with the JSON API?
- index.php template is used instead of blog page
- Prevent private post 404
- Where is the /blog/ url set from?
- NextGen Gallery template cache [closed]
- Adding variable to get_template_part
- Set template based on query in URL
- Template tags for Buddypress
- ACF image field to WordPress featured image
- Child theme template file will not load
- How to display only an excerpt of the content with custom post types?
- get_template_part returns NULL
- ACF – Theming Flexible Content
- Display “large” image size and show caption in attachment page
- How to delete read more span on single post view?
- WordPress editable template fields
- How do I find the directory of a page template?
- Conditionally display different images before the content in a page template
- Show all parts in multipage post
- One of my pages uses the archive.php template only. Why?
- Why are 404s not triggering my 404.php template?
- Is there a way to create a block template that is not limited to a post type?
- Combining ‘depth’ with ‘include’ in wp_list_pages()
- How to use same page template if post status other than ‘publish’?
- link to non-category page routed to category template
- Can’t format content of Rich Text Editor in Template
- get_file_data to read data for Custom Template File?
- Footer.php not showing?
- How to publish a Page and Posts using single template
- lost css when overriding themes templates
- What is the best practice to style archive page 2,3,etc differently than archive.php?
- How to create a post template with two sidebars
- ACF costum date format [closed]
- != and !== both not always working? [closed]
- Page template for a site from network
- WordPress 3.3.1 single post template
- Author template help. How to check if field exists in the profile?
- Conditional to determine if search.php page is the current template
- Prevent 404 and serve custom template for custom URL
- Page Templates not using functions.php
- Add stylesheet per layout
- use a custom page to display search results
- When a user registers, create a page from an existing template with their username as the page name
- Theme settings Page: Settings Api vs Update_Options
- How to add description over forum list on bbpress root page
- two active templates for one post
- Where is the code for “Front Page Template”?
- Help Understanding Template Hierarchy
- what is template-name.php
- templates with page teasers Or Featured Items
- If Child or Grandchild of Page
- Page template not registering on theme
- Is it possible to create custom links inside a template?
- How do I custom a page that doesn’t exist in the page list?
- Uncaught Error: Call to undefined function twentytwenty_the_post_meta()
- Timber + MtHaml, or any other HAML-like HTML shorthand
- small problem in the article ()
- Unable to access wordpress page
- How to configure my blog page
- Accidentally deleted code in header.php
- BuddyPress : how can I call the template WordPress would have chosen (template hierarchy)?
- How can I make custom page templates work on child theme?
- Archive only for /year/month, not terms
- Why default template does not show?
- Why does the blog page not take the page template selected?
- plugin overwrites other plugin’s archive-.php file
- Custom Taxonomy Theme file not routing correctly
- Why would adding a template file to a child theme cause an error in template-loader.php?
- How can I make is_page_template() workable in child theme?
- How can I add some blocks to template without changing template file?
- Creating a popup
- Templates for Mobile Site
- WordPress not picking up custom templates in sub directory
- Category template not displaying all post formats
- Is it possible to call a template file inside wysiwyg editor? And how?
- Retrieving post ID from current page
- Mysterious template change after database import/export
- Is there a way to share a template/markup with the JSON API so that it doesn’t need to be declared both in PHP and in JS?
- Styling own template
- WordPress sites translate dynamically generated Homepages
- changes to templates not showing on server
- Why is this page using the homepage template and not the one it should?
- Single template will not show sidebar/bottom-nav and footer
- Problem with permalink structure for WordPress custom post_type archive template
- Make default template two columns?
- Read more button not working
- pass dynamic value to page to pull in categorised post cards
- Dynamic header and footer template inclusion: footer script not included