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
- Can I force WP_Query to return no results?
- Page template query with WP_Query
- Multiple WP_Query loops with Pagination
- WP_Query and next_posts_link
- Too slow when using both ‘tax_query’ and ‘meta_query’ both in WP_Query
- Get array of posts from the current archive page loop
- How-to exclude terms from the main query the most performant way?
- Pagination with WP_Query is buggy – working for some pages, but not the others
- Get the number of posts from the current page results
- How can I save an array from a random post sequence for later use?
- Does WordPress generate an automatic page for post formats?
- In loop: posts have thumbnail AND other variables
- How to order category.php loop by ‘meta_value’?
- Add inline HTML to posts published within last 24hrs
- Move posts to top of WP_Query if in certain Taxonomy?
- Single page theme
- Display different number of posts from one category on the different pages
- How to change a custom query into a standard loop?
- Injecting content with $wp_query->current_post restarts from zero on paged pages. How to inject content after X posts, regardless of pagination?
- Front End Sorting Questions
- How to show the posts of some category first, and then all other
- wordpress query in header won’t reset and corrupts other loops
- Pagination stops at page 6
- Paginated HTML Sitemap
- How to limit total number of posts in wp query loop?
- 2 loops on page – one with orderby rand second orderby date
- Undefined WP_Query::has_posts()?
- Create ONE callback for all page templates, post filter queries + paginated pages, triggering pagination via AJAX
- Pagination is broken and I need help fixing it
- How to use WP_Query to display many posts?
- Counter problem, infinite loop when post_per_page equals X
- Five posts from a category in footer
- Get a post from other loop each n-posts in the main loop
- Loop returning only 1 result
- How to get all unique categories for posts in loop?
- Using the_post_thumbnail resets current loop item ID
- Order by empty custom field
- Post loop for all taxonomy terms
- New WP_Query loop in admin causes problems
- Need to convert string of term ids into comma separated integers for use in an arguments array
- How do I get my custom query to work with search results after the first page?
- Issue with front page navigation after upgrading to 3.4
- Exclude recently updated post from custom WP_Query using multiple loops
- get_posts output always same post
- How to use WP_Query() on single.php?
- difference between querying database and using the loop
- Stomping WP_Query in author archive to facilitate pagination with custom queries
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Loop increase in while loop not working
- posts archive page – closing WP_Query loop correctly [closed]
- has_excerpt() not working inside wp_query
- AJAX Breaking Offset Argument In WP Query
- Continue or break the while loop
- Loop posts based on permalink term
- Save (and exclude) posts from loop to use in another loop on page
- Get all posts with empty meta_value
- Does putting queries within loops cause an issue on WordPress?
- Function using get_posts() with tax_query not working when called from functions.php
- How to get current page nearest parent id?
- How to create Page templates for showing Blog posts in different layouts?
- Print the whole page?
- Interrogate a page within a loop to check template type or custom meta data (Pages vs Posts)
- How to make the ‘request’ filter work?
- How do I stop the same post showing multiple times in a archive?
- how to get custom attachment url?
- Display posts side by side with custom query
- WP_Query & Duplicate entries
- WordPress For Loop Prints Unwanted Extra Paragraph Element
- Calling a function with WP_Query only ever brings the first result
- 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?
- Fetching $_POST from Page Template into functions.php
- Ordering Posts by parent category, name ascending
- Create multiple sections for all categories and then queries all the posts for each of those categories
- Multiple wp_query loops showing first 5 posts on all pages instead of older posts[Resolved]
- Next / previous posts link doesn’t show up with Posts 2 Posts
- $query conflicting with other queries in the same page
- Carousel Loop only duplicating
- How to show featured post first, then separate loop for other posts
- Query All Posts: Either Display Most Recent or One with Particular ACF Value Chosen