Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8026525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:31:15+00:00 2026-06-04T23:31:15+00:00

I am trying to develop a query for WordPress that will allow me to

  • 0

I am trying to develop a query for WordPress that will allow me to display a list of child pages with titles only, and then under each child page title, a list of grandchilden (children of the child) page titles AND their content.

So for example, the output should be something like this:

<ul>
  <li>
    <h1>Page 1</h1>
    <ul>
      <li>
        <h2>Child Page 1</h2>
      </li>
      <li>
        <h2>Child Page 2</h2>
        <ul>
          <li>
            <h3>Grandchild</h3>
            <p>Hello, welcome to this grandchild page</p>
          </li>
          <li>
            <h3>Grandchild #2</h3>
            <p>Hello, welcome to this grandchild page</p>
          </li>
        </ul>
      </li>
      <li>
        <h2>Child Page 3</h2>
      </li>
    </ul>
  </li>
  <li>
    <h1>Page 2</h1>
  </li>
</ul>

It needs to be done dynamically, meaning I do not want to specify the post ID number as part of the query.

I have tried using a standard WordPress Query and then nesting a second query within the first one – this failed.

In addition, I also tried modifying the code seen here: http://wordpress.org/support/topic/query-child-pages-of-a-current-page-and-loop-through-each-child-page

Finally, I also tried to modify this code:

<?php if ( have_posts() ) {  while ( have_posts() ) { the_post(); $thispage=$post->ID; }} ?>
<?php $childpages = query_posts('post_per_page=3&orderby=menu_order&order=asc&post_type=' . get_post_type( $post->ID ) . '&post_parent='.$thispage);
    if($childpages){ /* display the children content  */
            foreach ($childpages as $post) :
            setup_postdata($post); ?>
          <li><a class="" href="#<?php echo($post->post_name) ?>">
            <?php the_title(); ?>
            </a></li>
          <?php
      endforeach;
     } ?>

I’ve been trying to get this working for more than a day now and i’m just going around in circles really.

Would very much appreciate help in getting this working.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:31:16+00:00Added an answer on June 4, 2026 at 11:31 pm

    This should work for you, it only goes 1 level deep but you should get the gist.

    echo "<ul>";    
    if ( have_posts() ) {
        while ( have_posts() ) {
            the_post();
            echo "<li><h1>".get_the_title()."</h1>";
    
            $args=array(
                    'orderby' => 'menu_order',
                    'order' => 'ASC',
                    'posts_per_page' => 3,
                    'post_type' => get_post_type( $post->ID ),
                    'post_parent' => $post->ID
            );
    
            $childpages = new WP_Query($args);
    
            if($childpages->post_count > 0) { /* display the children content  */
                echo "<ul>";
                while ($childpages->have_posts()) {
                     $childpages->the_post();
                     echo "<li><h2>".get_the_title()."</h2></li>";
                }
                echo "</ul>";
            }
            wp_reset_query();
    
            echo "</li>";
        }
    }
    echo "</ul>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to develop a small app, that will store User's input about
I am trying to develop a T-SQL query which will do the following: ROUND(100
My scenary: I am trying to develop a service which will query different databases.
I've been trying to develop a linq query that returns the ItemNumber column of
The query I'm trying to develop return the following: The total amount of units
I'm trying to develop this code: $users = $facebook->api(array( 'method' => 'fql.query', 'query' =>
I am trying develop a basic referrer system to my Django website, system will
im trying to develop an app for a win CE mobile device that downloads
So I am trying to develop a app that lets you see the current
I'm trying to develop a simple list of monthly archives for my site's blog.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.