have_comments() WordPress Function

The have_comments() function is used to check if there are any comments for a post in WordPress. This function can be used within the WordPress loop to check if a post has any comments before display them.

have_comments() #

Determines whether current WordPress query has comments to loop over.


Return

(bool) True if comments are available, false if no more comments.


Top ↑

More Information

This function relies upon the global $wp_query object to be set – this is usually the case from within The Loop.

Warning: this function will always return “false” until after comments_template() has been called. If you need to check for comments before calling comments_template(), use get_comments_number() instead.


Top ↑

Source

File: wp-includes/query.php

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


Top ↑

Changelog

Changelog
VersionDescription
2.2.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.