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?
- WP_Query: Show 10 posts in date order, first three random
- get_delete_post_link() inside Loop stubbornly returns nothing
- loop inside the foreach
- postsperpage value not being applied
- query_posts clarification needed
- 2 queries with counters
- I am officially missing something about transient posts
- Why doesn’t my WP Meta Query return any results?
- Paginate pages with dynamic query
- 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
- Determine if ID is page or post and query the ID
- Custom template for password protected page
- Exclude posts based on an array
- Query post & loop problem.
- Exclude current post ID from loop in sidepbar.php
- Avoid WP_Query’s duplicate posts with taxonomies
- Ascending order has strange effects on wordpress loop
- Magazine style frontpage with multiple categories/loops and no duplicate posts
- Custom Post Type Query W/Category Dropdown
- Loops for cat links not looping for wordpress site
- How do I set the Stewart Search Template to return only published posts in the result
- Filter products on category AND tag
- 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
- Trying to get all links in my posts
- Duplice post with standard WP loop – fixed by using query_posts() instead
- pre_user_query vs pre_get_posts
- How do I stop the same post showing multiple times in a archive?
- Get posts that match defined arrays of tags
- 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
- Problem with my loops
- I need query_posts() to order results first by a meta value and then by post ID
- WP_Query & Duplicate entries
- WordPress For Loop Prints Unwanted Extra Paragraph Element
- Build a Page which shows the Oldest Post with specific Custom Field Value
- 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
- My entry results are not consistently alphabetized
- Merge two queries and remove duplicate
- How to order posts, that have already been filtered by custom taxonomy, by their category names?
- How to add in WP_Query to every 3 posts displayed? [duplicate]
- WP Query Relations / Compare
- how to show more than 1 post into three columns query
- How to fix pagination for custom loops?
- Get featured image outside the loop using foreach
- query_posts() doesn’t seem to be called in my page
- Some doubts about how the main query and the custom query works in this custom theme?
- Create a hierarchical loop at predefined markup requirements
- Alternative layout the loop
- Show posts by tags excluding current post
- WP_Query secondary query failing
- Sort / Filter Queries
- Is it possible to add query parameters on the archive page?
- Strange problem with wp_get_attachment_image_src database (db) query count
- Optimising specific Query with ACF meta objects
- display news with pictures 3 small and one large (loop)
- Loop through multiple custom fields with increasing number
- Advanced Post Display/Pagination/Ordering
- Why I have this strange behavior when I try to exlude the featured post from posts visualization?
- Next 10 posts data of currently viewing post in blog page
- How to organize a WP_Query’s list of posts by category and display category title?
- How to fix pagination for custom loops?
- When should you use WP_Query vs query_posts() vs get_posts()?
- meta_query dates from an array
- Adding a category at even positions on main loop with modified pagination
- Query counting excluded category on paged loop
- Query Posts From Multiple Post Types
- get_posts and wp_autop (remove filter)
- How to fix pagination for custom loops?
- How to query post ids liked by the Author
- How to fix pagination for custom loops?
- query_posts ignores the argument
- Converting an existing query_posts to WP_Query
- WordPress Query showing multiple titles
- Query Posts by date range with fixed beginning and end
- custom query to get posts
- The Loop isn’t working
- Get query result before posts are displayed?
- Twitter bootstrap carousel multiple items in carousel
- WP-Snap too slow (caused by WP_Query?)
- Combine Query and Select Database to create directory loop
- show posts from one category with comments only
- Multiple loop for “featured” items returns wrong posts