Determines whether current WordPress query has posts to loop over.
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.
function have_posts() {
global $wp_query;
if ( ! isset( $wp_query ) ) {
return false;
}
return $wp_query->have_posts();
}
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/have_posts