Title: comment_exists
Published: April 25, 2014
Last modified: February 24, 2026

---

# comment_exists( string $comment_author, string $comment_date, string $timezone ): string|null

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/comment_exists/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/comment_exists/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/comment_exists/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/comment_exists/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/comment_exists/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/comment_exists/?output_format=md#changelog)

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

Determines if a comment exists based on author and date.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/comment_exists/?output_format=md#description)󠁿

For best performance, use `$timezone = 'gmt'`, which queries a field that is properly
indexed. The default value for `$timezone` is ‘blog’ for legacy reasons.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/comment_exists/?output_format=md#parameters)󠁿

 `$comment_author`stringrequired

Author of the comment.

`$comment_date`stringrequired

Date of the comment.

`$timezone`stringrequired

Timezone. Accepts `'blog'` or `'gmt'`. Default `'blog'`.

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

 string|null Comment post ID on success.

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

    ```php
    function comment_exists( $comment_author, $comment_date, $timezone = 'blog' ) {
    	global $wpdb;

    	$date_field = 'comment_date';
    	if ( 'gmt' === $timezone ) {
    		$date_field = 'comment_date_gmt';
    	}

    	return $wpdb->get_var(
    		$wpdb->prepare(
    			"SELECT comment_post_ID FROM $wpdb->comments
    			WHERE comment_author = %s AND $date_field = %s",
    			stripslashes( $comment_author ),
    			stripslashes( $comment_date )
    		)
    	);
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/comment.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/comment.php#L26)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/comment.php#L26-L42)

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

| Uses | Description | 
| [wpdb::get_var()](https://developer.wordpress.org/reference/classes/wpdb/get_var/)`wp-includes/class-wpdb.php` |

Retrieves one value from the database.

  | 
| [wpdb::prepare()](https://developer.wordpress.org/reference/classes/wpdb/prepare/)`wp-includes/class-wpdb.php` |

Prepares a SQL query for safe execution.

  |

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

| Version | Description | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Added the `$timezone` parameter. | 
| [2.0.0](https://developer.wordpress.org/reference/since/2.0.0/) | Introduced. |

## User Contributed Notes

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