I am currently having an issue with memory when my site tries to generate a tree of child pages. to my understanding query is too large (WP has 60000 pages)

following is code i am using

 ?php global $post;
      wp_list_pages( array(
      'child_of' => $post->ID, // Only pages that are children of the current page
      'depth' => 1 ,   // Only show one level of hierarchy
      'sort_order' => 'asc',
      'title_li' =>$post->post_title

Is there any additional arguments i can add to make the query smaller or is there any better way of displaying a list of child pages?

Thank you in advance.

  • Limit the query... and fetch using AJAX... Nov 16, 2016 at 13:13
  • @VishalKumarSahu would you have a suggestion on implementation of ajax as i am very novice to it Nov 16, 2016 at 14:10
  • AJAX is good for your case... Begin with it... Nov 16, 2016 at 15:29

3 Answers 3


WP_Query has Pagination_Parameters like posts_per_page and offset to help you out. Just page the results to limit the query to a more reasonable number per page.

  • im not trying to pull all 60000. what im doing is a page that may be located 3 levels into the hierarchy tree and display a list of all pages that are children of it (10-40 pages) Nov 16, 2016 at 14:09
  • Well, this would make your query smaller... Same with date range
    – jgraup
    Nov 16, 2016 at 14:50
  • used wp_query in the end thank you very much will post solution now Nov 22, 2016 at 9:41

I can't see any wrong in your code, maybe you should check that whether you can got correct post id via $post->ID, sometimes some code before yours changed $post object cause that you can't get it and wp_list_pages() will display all pages.

  • it displays 50 % of the time and the other 50 i get out of memory error which i think is caused by query checking far too many pages Nov 16, 2016 at 15:14
  • Execution time and such things are there... Nov 16, 2016 at 15:28
  • No, i'm not saying execution time, like you replied in another answer, you are not trying to pull 60000 results, just 10-40 pages. if the post_id specified to child_of is correct, it should only return the child pages, most time it will not spend more than 1 second.
    – Cl0udSt0ne
    Nov 16, 2016 at 15:44
  • <?php global $post; wp_list_pages( array( 'child_of' => $post->ID, // Only pages that are children of the current page 'depth' => 1 , // Only show one level of hierarchy 'sort_order' => 'asc', 'title_li' =>$post->post_title ));
    – Cl0udSt0ne
    Nov 16, 2016 at 15:44
  • var_dump($post); before your code, and check it.
    – Cl0udSt0ne
    Nov 16, 2016 at 15:45

To shorten the execution time i ended up using WP_Query as suggested by jgraup

the code to generate list of children is below

<?php global $post;
  echo '<p>'. get_the_title().'</p>'; // current post title
  $query = new WP_Query( array( 'post_type' => 'page', 'post_parent' => $post->ID,'order'   => 'ASC') ); // find all pages with parentId of current page id 
      if ( $query->have_posts() ) {
          echo '<ul>'; 
          while ( $query->have_posts() ) {//loop through results
            echo '<li><a href='. get_page_link($post->ID) .'>' . get_the_title() . '</a></li>';//li with link to the page
          echo '</ul>';
          /* Restore original Post Data */
        } else {
          // no posts found


Your Answer

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

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