Try something like:
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="parent-post">
<?php the_title('<h2>', '</h2>'); ?>
<?php $children = new WP_Query( array('post_type' => 'page', 'post_parent' => get_the_ID() )); ?>
<?php if ( $children->have_posts() ) : ?>
<ul class="post-children">
<?php while ( $children->have_posts() ) : $children->the_post(); ?>
<li><?php the_title('<h3>', '</h3>'); the_content(); ?></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
Related Posts:
- Query last updated posts (posts updated in the last 24 hours)
- WP_Query vs get_posts
- Query Custom Meta Value with Increment
- Is `query_posts` really slower than secondary query?
- Are there any scenarios where the query_posts may be used?
- 3 Posts in Loop, Show Stickies First
- How to display posts by vote count and if no value continue with latest posts with no votes?
- Include current post into loop
- Should I reset $wp_query?
- Query posts only with actual text content (not including shortcode or images)
- Ordering Posts by parent category, name ascending
- Why I obtain this WP_Query strange behavior trying to select posts having a specific tag?
- Should we trust the post globals?
- WP_Query: query posts by ids from array?
- pre_get_posts with get_posts
- Identify which loop you are hooking into; primary or secondary?
- Why is it necessary to call rewind_posts() when using the loop more than once? [duplicate]
- Retrieving 3 latest post from each of 5 different custom post types
- Transient pagination not working properly
- post loop causes wp_users and wp_usermeta DB queries for each users
- Query for posts in 2 taxonomies
- Pass the same object to multiple widgets in a template with one query
- Upcoming Event: How do I sort database by custom date field, but ignore past dates?
- Improving WP_Query for performance when random posts are ordered
- Query posts by specific word on title
- Better way to display posts from specific categories, in a grid layout
- How to query a custom post type with a taxonomy filter but display post type archive page?
- Loop after page content
- Tricky WP Query
- A loop with all articles with certain text strings in tags
- Change query_posts to WP_Query in page but does not work
- Display most viewed post from last 30 days is not working correctly
- WP_Query condition affects posts_per_page count
- How to go about combining dropdowns / filter queries?
- Query reset problem or flawed code to enable custom post type query
- Why WP_Query(‘showposts=5’) shows only 1 post?
- Custom Query num_rows returns wrong amount
- Using ajax with paging and a custom sub-query
- Slow page loads due to WordPress Core Query
- How do I use AJAX Query in my posts loop?
- woocommerce get_price_html not pulling in correct price
- Make blog page show 10 on first page, 9 on every other page
- How to fix pagination for custom loops?
- How can I paginate this?
- How to fix pagination for custom loops?
- posts_per_page option limits the number of Gallery items
- Custom loops, sticky posts, and pagination nightmare
- pagination not working for category.php (custom post types in categories)
- Making a query to the DB using same parameters of loop
- Is_single() conditional tag returns null in query
- How do I rewrite this loop as a new WP_Query style-loop?
- Loop inside query
- How to provide meta_key array to wp_query?
- How to add div blocks after certain set of post
- Exclude taxonomy term from all loops, but having it on widget
- How can I access specific posts brought back by query_posts?
- Query for first 3 posts to change the look and feel
- How to give classname to post if post has no content?
- Separate First Post Loop
- loop inside the foreach
- postsperpage value not being applied
- 2 queries with counters
- Custom Post type showing up in loop, regular posts are not showing up
- Display 3 posts with different HTML markup using a loop
- Performance concerns: index.php vs taxonomy-$taxonomy.php
- Custom template for password protected page
- Avoid WP_Query’s duplicate posts with taxonomies
- Why does my WP_Query pagination on a custom page.php only loads the homepage?
- Get a Post Loop based on Logged in User information into a Shortcode
- Custom Query with Sticky Posts
- how to add 4 post in one carousel slide
- Custom query for custom post type not getting correct post ID
- Show 5 posts and than 3 posts offset with pagination
- How to show post title in content editor in backend?
- Query posts and display all dates in repeater field in chronological order
- Merge two queries and remove duplicate
- Get featured image outside the loop using foreach
- Create a hierarchical loop at predefined markup requirements
- Sort / Filter Queries
- Is it possible to add query parameters on the archive page?
- Loop through multiple custom fields with increasing number
- Why I have this strange behavior when I try to exlude the featured post from posts visualization?
- How to organize a WP_Query’s list of posts by category and display category title?
- Adding a category at even positions on main loop with modified pagination
- Query Posts From Multiple Post Types
- get_posts and wp_autop (remove filter)
- Converting an existing query_posts to WP_Query
- WordPress Query showing multiple titles
- custom query to get posts
- Twitter bootstrap carousel multiple items in carousel
- WP-Snap too slow (caused by WP_Query?)
- Combine Query and Select Database to create directory loop
- Multiple loop for “featured” items returns wrong posts
- Least Number of Loops to Create Custom Homepage?
- wordpress showing all posts instead of date range
- Pagination in category.php not functioning
- How to do query_posts on tags pages
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise
- Show number of posts AND number on current page (cannot make it work)
- Query Loop Block: possible to restrict just child pages?