update_comment_meta()WP 2.9.0

Updates or adds metadata for the specified comment.

The function can be used instead of add_comment_meta() - adds comment metadata.

The function first checks if the specified meta-field key exists; if it does not exist, a new field is created; if it exists, the field is updated.

Comment metadata is stored in the wp_commentmeta table.

No Hooks.

Returns

Int|true|false. Depends on the result of the operation.

Usage

update_comment_meta( $comment_id, $meta_key, $meta_value, $prev_value );
$comment_id(integer) (required)
ID of the comment whose additional data needs to be changed.
$meta_key(string) (required)
Key of the field that needs to be changed.
$meta_value(string) (required)
New value of the key.
$prev_value(string)
Old value of the key (under one key there can be multiple values, so in some cases it is necessary to specify which value needs to be updated).
Default: ''

Examples

0

#1 Update the metadata of comment 3416:

update_comment_meta( 3416, 'my_key', 'Brad' );

Now use function get_comment_meta() to get comment metadata:

$value = get_comment_meta( 3416, 'my_key', true );

echo $value; //> Brad

Changelog

Since 2.9.0 Introduced.

update_comment_meta() code WP 6.9

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