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.


Top ↑

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.


Top ↑

Source

File: wp-includes/query.php

function have_posts() {
	global $wp_query;
	return $wp_query->have_posts();
}


Top ↑

Changelog

Changelog
VersionDescription
1.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.