As per wordpress codex, the_post() “Iterate the post index in The Loop. Retrieves the next post, sets up the post, sets the ‘in the loop’ property to true.” This all occurs within the post object itself.
If you only have 1 post, and run the_post twice, you’ll reach the end of the post count. In this case, even doing a var_dump of the_post still runs the function, which is why you’re not seeing results below…you’ve already reached the end of the loop before you start trying to output data.
Also “This function does not return any values.”
Meaning your var_dump will always return null, because you’re dumping the results of a function which returns nothing.
If you want useful results, var_dump($category_posts) will return the post object, which will contain any posts found and other information. ->the_post is just a method of the post object itself.
Related Posts:
- Two loops on archive page
- Check if loop has any categories?
- How to make search for posts using get method?
- Wp_query with 2 meta keys and array of meta values
- WP_QUERY wrong ammount of posts
- Writing less unnecessary code with WordPress
- How to separate two columns from one content on a page template?
- WooCommerce | AJAX | Product Pagination | Help me implement Ajax Pagination
- Second WP_Query loop shows data from main query
- active link for most recent post on vertical tabs
- Get author meta data with no published posts in author.php?
- Resetting post data to previous loop in nested loops
- Pagination returns 404 after page 20
- Make loop display posts by alphabetical order
- get custom post type by tag
- How to get order of posts?
- Identify which loop you are hooking into; primary or secondary?
- Group posts by custom field
- Trying to list out child pages with WP_Query
- Pagination is not working using WP_Query
- Transient pagination not working properly
- get_posts() seemingly ignoring post_type
- Woocommerce custom loop to show all the products [closed]
- Exclude first 5 posts of specific categories in the main loop
- Why execute the_post()?
- Multiple WP_Query loops with Pagination Not Working
- Posts loop with pagination on a single post page
- WP_Query Order by Specific Post ID First
- How to change posts order on Category and Tag archives?
- WooCommerce Only OnSale Products Loop Snippet [closed]
- Apply CSS class to every second database record [closed]
- ACF – Get lowest & highest value from field
- Using one WP_Query object within the loop of another WP_Query object
- WP_Query on custom field and order results
- how to merge a WPQuery array with a PHP array and use the Loop to Output the result
- How to display 7 most recent days of posts?
- Create A Loop With A Variable Number of Posts For Each Bootstrap Row?
- Where is the WP_Query instance instantiated (when working with themes)?
- Custom Search Not Consistent with Results
- Display both standard posts in a specific category along with a custom post type in a single loop?
- Orderby is working with one query but not with other
- Show post number in widget loop
- posts_per_page not working for first page of pagination
- Loop Performance > JSON files vs. WP_Query vs. REST API
- How to order posts by title after they have already been sorted by category
- Search form not working with custom query?
- WordPress ignoring LIMIT / posts_per_page despite being in wp_query
- Conflict with get_posts and the_content
- Array as ‘key’ in WP_Query
- How do I rewrite this loop as a new WP_Query style-loop?
- How to provide meta_key array to wp_query?
- Adding a html class based on post count
- Trying to retrieve random post, getting a page
- Meta query compare for ID’s greater than specific ID
- PHP – Loop custom post type categories within jQuery Tabs
- WP_Query with one category in args shows other categories
- Ordering posts by custom field and grouped by month
- Hiding carousel indicators if there’s only one post
- relation OR instead of AND – Filtered term ID’s in loop
- Compare “Main” post ID to ID inside wp_query loop
- Performance concerns: index.php vs taxonomy-$taxonomy.php
- Why does apply_filters behave different inside and outside a loop?
- Custom template for password protected page
- WP Query get only 1 post (sticky, not sticky etc)
- WP_Query not returning correct result with meta_query parameter
- problem with the loop
- How can I do a orderby by the number of items? So basically list by starting with the array with the largest number of post
- Function the_posts_pagination() not compatible with WP_Query arguments
- Prevent Duplicate Post Counted by Query
- How to show specify category template for both parent and child category
- Pagination inside the blog page not working
- Woocommerce featured products query no longer working
- Custom Query Pagination not working on static front page
- query all posts published by certain user id
- the_post_thumbnail and multiple WP_Query
- I have 3 categories, i want to display on a loop the last 3 of every category
- WP_Query doesn’t works inside loop
- modifying the loop multiple times with arguments passed through ajax to wp_query
- WP_Query causing links to not work
- Retrieving category pages from subcategory returns empty sets
- 2 Loops on one page – pagination of 2nd loop ignore array of excluded posts
- How to solve this script problem in theme directory?
- Iterate through ID’s in loop
- Loop through multiple custom fields with increasing number
- Different number of posts showing in development vs production server
- An archive page without post format (just standard post)
- How to show the posts list into a static page? Problems to use the loop into a static page
- No content found on page 2 of pagination with 1 post per page
- Pull Instagram images into an existing loop?
- Multiple loop for “featured” items returns wrong posts
- issue displaying variations in custom template using WPeC 3.8.9.2
- Pagination in custom query not working [duplicate]
- Help with showing text when something is entered in my search bar
- How to write a query-function as a query-shortcode?
- Print post data inside loop using theme content template
- First post outside of loop, homepage only?
- 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 WordPress loop, articles not in same order as Array
- Why ignore_sticky_posts argument is in sticky post query?