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

---

# update_comment_meta( int $comment_id, string $meta_key, mixed $meta_value, mixed $prev_value ): int|bool

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/update_comment_meta/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/update_comment_meta/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/update_comment_meta/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/update_comment_meta/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/update_comment_meta/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/update_comment_meta/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/update_comment_meta/?output_format=md#user-contributed-notes)

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

Updates comment meta field based on comment ID.

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

Use the $prev_value parameter to differentiate between meta fields with the same
key and comment ID.

If the meta field for the comment does not exist, it will be added.

For historical reasons both the meta key and the meta value are expected to be “
slashed” (slashes escaped) on input.

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

 `$comment_id`intrequired

Comment ID.

`$meta_key`stringrequired

Metadata key.

`$meta_value`mixedrequired

Metadata value. Must be serializable if non-scalar.

`$prev_value`mixedoptional

Previous value to check before updating.
 If specified, only update existing metadata
entries with this value. Otherwise, update all entries. Default empty string.

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

 int|bool Meta ID if the key didn’t exist, true on successful update, false on failure
or if the value passed to the function is the same as the one that is already in
the database.

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

    ```php
    function update_comment_meta( $comment_id, $meta_key, $meta_value, $prev_value = '' ) {
    	return update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value );
    }
    ```

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

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

| Uses | Description | 
| [update_metadata()](https://developer.wordpress.org/reference/functions/update_metadata/)`wp-includes/meta.php` |

Updates metadata for the specified object. If no value already exists for the specified object ID and metadata key, the metadata will be added.

  |

| Used by | Description | 
| [wp_update_comment()](https://developer.wordpress.org/reference/functions/wp_update_comment/)`wp-includes/comment.php` |

Updates an existing comment in the database.

  |

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

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

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

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/update_comment_meta/?output_format=md#comment-content-1440)
 2.   [Codex](https://profiles.wordpress.org/codex/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/update_comment_meta/#comment-1440)
 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%2Fupdate_comment_meta%2F%23comment-1440)
    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%2Fupdate_comment_meta%2F%23comment-1440)
 4. **Basic Usage**
 5.     ```php
        <?php update_comment_meta( 3416, 'my_key', 'Brad' ); ?>
        ```
    
 6.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fupdate_comment_meta%2F%3Freplytocom%3D1440%23feedback-editor-1440)

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