WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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? :)

share|improve this question
up vote 0 down vote accepted

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
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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