Title: have_comments
Published: April 25, 2014
Last modified: August 20, 2026

---

# have_comments(): bool

## In this article

 * [Return](https://developer.wordpress.org/reference/functions/have_comments/?output_format=md#return)
 * [More Information](https://developer.wordpress.org/reference/functions/have_comments/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/functions/have_comments/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/have_comments/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/have_comments/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/have_comments/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/have_comments/?output_format=md#wp--skip-link--target)

Determines whether current WordPress query has comments to loop over.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/have_comments/?output_format=md#return)󠁿

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

## 󠀁[More Information](https://developer.wordpress.org/reference/functions/have_comments/?output_format=md#more-information)󠁿

This function relies upon the global `$wp_query` object to be set – this is usually
the case from within [The Loop](https://developer.wordpress.org/themes/basics/the-loop/).

Warning: this function will always return “false” until after [comments_template()](https://developer.wordpress.org/reference/functions/comments_template/)
has been called. If you need to check for comments before calling [comments_template()](https://developer.wordpress.org/reference/functions/comments_template/),
use [get_comments_number()](https://developer.wordpress.org/reference/functions/get_comments_number/)
instead.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/have_comments/?output_format=md#source)󠁿

    ```php
    function have_comments() {
    	global $wp_query;

    	if ( ! isset( $wp_query ) ) {
    		return false;
    	}

    	return $wp_query->have_comments();
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/query.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/query.php#L1041)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/query.php#L1041-L1049)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/have_comments/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Query::have_comments()](https://developer.wordpress.org/reference/classes/wp_query/have_comments/)`wp-includes/class-wp-query.php` |

Determines whether there are more comments available.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/have_comments/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.2.0](https://developer.wordpress.org/reference/since/2.2.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/have_comments/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/have_comments/?output_format=md#comment-content-1220)
 2.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/have_comments/#comment-1220)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhave_comments%2F%23comment-1220)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhave_comments%2F%23comment-1220)
 4. **Basic Example**
 5. Example based on Twentyten’s comments.php template: Comments title (and more) is
    displayed only when comments are available:
 6.     ```php
        <?php if ( have_comments() ) : ?>
        	<h3 id="comments-title"><?php
        		printf(
        			_n( 'One Response to %2$s', '%1$s Responses to %2$s', get_comments_number(), 'twentyten' ),
        			number_format_i18n( get_comments_number() ),
        			'<em>' . get_the_title() . '</em>' 
        		);
        	?></h3>
        // [and more, of course...]
        <?php else : // or, if we don't have comments:
        	if ( ! comments_open() ) : ?>
        		<p class="nocomments"><?php _e( 'Comments are closed.', 'twentyten' ); ?></p>
        	<?php endif; // end ! comments_open() ?>
        <?php endif; // end have_comments() ?>
        ```
    
 7.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhave_comments%2F%3Freplytocom%3D1220%23feedback-editor-1220)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhave_comments%2F)
before being able to contribute a note or feedback.