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
- sort and display posts by custom field (wp-query and the loop))
- How to create custom query by keyword in post title?
- difference between querying database and using the loop
- If have posts a week old, display, else display a different loop
- WP_Query – Adding “offset” posts to the end of 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]
- Conditional operator OR not working with custom fields
- Pagination on template page for custom query redirecting to index.php
- Loop increase in while loop not working
- Get posts that do not have the same tags as current
- posts archive page – closing WP_Query loop correctly [closed]
- has_excerpt() not working inside wp_query
- All blog data on a page using custom query gives 404 for page 2 and onward
- wp_query is showing posts from other categories
- Daily drip of posts – based on user ‘startData’ – ordered oldest to newest
- How to add tax_query to $args with concatenation
- Should I reset $wp_query?
- Meta query compare for ID’s greater than specific ID
- Exclude a Woocommerce product from WP_Query
- WP ForLoop to compare meta information of posts to determine what post to display
- AJAX Breaking Offset Argument In WP Query
- WP_QUERY wrong ammount of posts
- How to add sort order to incremented and paginated category loop
- WP_Query returns different results from get_posts() [closed]
- How does WP generate the default $query in WP_Query based on the URL?
- Continue or break the while loop
- How to filter query loop block with a search string from the query parameters
- how to get category`s slug in WP_Query 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
- How to split a post and intercalate elements from a loop
- How to remove only the latest sticky post from the loop
- WordPress Post Looping? [duplicate]
- How to do a loop inside a loop?
- Carousel Loop only duplicating
- Remove 5 latest posts from the loop
- Get next post when using pagination with WP_Query?
- Exclude post formats in custom loop
- Adding css tweak based on page template
- Get author meta data with no published posts in author.php?
- Query for page content, and query for posts on the same page?
- Can’t seem to get an else statement correct? [closed]
- Help with showing text when something is entered in my search bar
- How to write a query-function as a query-shortcode?
- How to show featured post first, then separate loop for other posts
- Output ACF field dynamicaly within a taxonomy loop [closed]
- Main loop querying current template’s info only in custom category archive pages, not my posts
- Print post data inside loop using theme content template
- Show linked products using wp query and woocommerce
- Standard Loop – wp_query
- tax_query not working properly with get_posts
- First post outside of loop, homepage only?
- How to write short code with if else to get page_id?
- the_excerpt() not working in custom archive
- How can I display sticky posts at first in wp_query?
- How do I split a large query with a semi-expensive function included into multiple smaller queries
- Custom Wp_query loop takes very long
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise
- Prevent WordPress loop from displaying similar post titles
- Custom query for certain post type OR another post type with a certain category
- Query All Posts: Either Display Most Recent or One with Particular ACF Value Chosen
- Show number of posts AND number on current page (cannot make it work)
- How to get rid of extra Untitled Article in html5 document outline when using new WP_Query?
- Custom WordPress loop, articles not in same order as Array
- after refresh the id that shows correct in first time click, changes to 1
- Pagination only showed when no category is set in wp_query
- WP_query shortcode inside acf Repeater breaks the repeater loop
- Unexpected number of loops in while
- Splitting query results, on the frontend, into separate sections based on meta value without multiple loops?
- How to display only posts from the last day with posts published?
- Rewrite URL custom search query
- Multiple queries and pagination
- Loop a Single Taxonomy and Output all Posts Associated (but also show a message for empty ones)
- Paginate_Links page 2 doesn’t work
- Post Query with Meta Query no longer working
- How to remove “MY WORDPRESS”” Label
- Need help with Query Loop. Need to get current taxonomy term and its posts and group them by a different selected taxonomy term
- Run a query for loop ordering by the sum of the inverse of comment age with WP_Query