I tested the query and it does work so the only thing I can spot that is misleading but not right is directly after you while() statement you have the_post(). This doesn’t work in secondary queries, it should look like:
<?php if( $subpages->have_posts() ) : ?>
<?php while( $subpages->have_posts() ) : $subpages->the_post(); ?>
...
<?php endwhile; ?>
<?php endif; ?>
Note the $subpages->the_post(); – since it’s a secondary query we need to continue referencing the query variable. After this all the normal loop functions work as expected, such as: the_title(), the_content(), etc.
Related Posts:
- How to use custom page for all posts with custom url, call another directory?
- How to display page content in a page template?
- Single page theme that uses pages for the content
- What are the differences between “Latest Posts” and “Static Page”?
- WP_Query doesn’t get sticky post at the top, when used in a page template
- Create a loop on my pages with new “WP_Query”
- Create a page template for “top rated posts” but show full content and not just a list
- inserting content of 1 Post to in another with a template hierarchy
- WP_Query with multiple orderby NOT working with ASC and DESC, what’s wrong?
- Display specific page (that is child) content on parent page
- Pagination for custom loop on custom page template is not displaying anything
- Determine if ID is page or post and query the ID
- Custom query does not find pages
- How to separate two columns from one content on a page template?
- display the children of the post using the current page as the main parent
- pages shortcode filtering by category
- How can I use a specific wordpress page template if certain words are used in page title [closed]
- Retrieving category pages from subcategory returns empty sets
- Issue in If else condition [closed]
- WordPress pagination returns the same posts
- Some doubts about how the main query and the custom query works in this custom theme?
- Using a custom WP_Query with get_template_part loop
- Loop within a loop?
- Use WP_Query with have_posts()?
- Display posts the match taxonomy term linked from wp_list_categoies?
- Merging a complex query with post_rewind and splitting posts into two columns
- Pagination Not working on Home Page with 2 Query
- meta_query not working properly
- Order by menu structure
- How to display 3 different loops in 3 columns on homepage
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- Can certain (site-crashing) limitations on WP_Query in shortcode be overcome?
- WP_Query to get posts in a specific category and post format
- Implementing an OR statement to wordpress wp_query
- Get List of all the Authors
- Can’t get drafts with WP_Query using post_status parameter
- Prevent duplicate post from dynamic multiple loops
- if/else on custom query gives 200 OK when condition not met?
- Multiple Loops Inside a Function
- Sticky posts are not showing at the top of category posts
- Storing query variable and then using wp_reset_query
- Create a loop that gets pages with their template
- Set order of returned items in the WP_Query() class/function
- list pages using page.php and NOT page-{slug}.php
- Show Sticky Post at the top but do not show again in the loop?
- Can I set my WP_Query to be a Main Query?
- Group and list posts by custom taxonomy
- Show scheduled posts in main loop but not in WP_Query?
- WordPress Pagination changes my template
- Change query based on post type while staying in loop
- Get a list of posts with associated meta_value
- add_filter(‘query_vars’) not working in custom template
- Out Of memory issue on post per page parameter
- $WP_Query: How to display excerpt on first post only
- How to make search for posts using get method?
- How to get list of posts from permalinks?
- Custom taxonomy.php not working
- different for loop if screen resolution < 1000px
- Transient api Caches confused
- get_template_part causes 500 error
- Exclude parent with child pages from WP_Query
- sort and display posts by custom field (wp-query and the loop))
- WP_Query – Adding “offset” posts to the end of the loop
- wp_query is showing posts from other categories
- WPQuery calling specific posts problem
- wp_query on page template not working (Genesis framework)
- Filtering by multiple conditions in the loop
- How to access $wp_query object from array of posts given by get_posts?
- Display all attached image of every post of custom post type and link to original post
- wp-query, pull children of parent page
- Writing less unnecessary code with WordPress
- WordPress Queries Not Working?
- Filter subpages in while loop from WP Query object
- Use have_posts() with array of post results retrieved by $wpdb->get_results
- How to sort by most watched in X days/months
- Magazine style frontpage with multiple categories/loops and no duplicate posts
- How can I use arrays and a foreach to generate many lists with WP_Query?
- display ACF repater field in archive page
- WP_Query breaking the loop in a nested loop
- Related posts queries
- INNER JOIN custom tables – SQL Query
- update_post_meta() not updating
- Paging works correctly on local version, but not live?
- How to add in WP_Query to every 3 posts displayed? [duplicate]
- why default wordpress loop not working outside index.php
- how to show more than 1 post into three columns query
- Display three sequential posts on each page load, without repeating previous
- Category Archive not working for pages
- active link for most recent post on vertical tabs
- custom query – offset to pagination
- Pagination not working with WP_QUERY
- wp_query pagination links producing 404
- get contents and permalink from a specified page
- How ‘secure’ are loops?
- Pagination problem with multiple loops on the same page
- How to do a loop inside a loop?
- Main loop querying current template’s info only in custom category archive pages, not my posts
- How can I display sticky posts at first in wp_query?
- Custom query for certain post type OR another post type with a certain category
- Splitting query results, on the frontend, into separate sections based on meta value without multiple loops?