have_posts() WordPress Function
The have_posts() function is used to check if there are any posts to display on a WordPress page. This function will return a boolean value (true or false) depending on whether there are posts available to display. If there are no posts available, then have_posts() will return false and no posts will be displayed on the page.
have_posts() #
Determines whether current WordPress query has posts to loop over.
Return
(bool) True if posts are available, false if end of the loop.
More Information
This function checks whether there are more posts available in the main WP_Query object to loop over. It calls have_posts()
method on the global $wp_query
object.
If there are no more posts in the loop, it will trigger the loop_end
action and then call call rewind_posts()
method.
Source
File: wp-includes/query.php
function have_posts() { global $wp_query; return $wp_query->have_posts(); }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
1.5.0 | Introduced. |