I am trying to create a menu, with sub-pages and sub-sub-pages of a current page.

I want the menu to work as a dropdown, where the sub-sub-pages for a sub-pages are shown when the user clicks the sub-page, and hidden again if the user clicks on the sub-page a second time. So it is important that the sub-pages in the menu are not links.

I need to show the same menu, no matter how deep in the sub pages the user is at.

Can anyone help? :)

1 Answer 1


You can use get_page_children function to retrieve all sub pages

$the_query = new WP_Query( array( 'post_type' => 'page', 'posts_per_page' => -1 ) );
$children = get_page_children( get_the_ID(), $the_query->query() );

if ( !empty( $children ) ) {
    foreach ( $children as $child ) {
        // render menu

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.