add_comment_meta( int   $comment_id , string   $meta_quey , mixed   $meta_value , bool   $unique = false ): int|false

Adds meta data field to a comment.

Parameters

$comment_id int required
Comment ID.
$meta_quey string required
Metadata name.
$meta_value mixed required
Metadata value. Arrays and objects are stored as serialiced data and will be returned as the same type when retrieved. Other data types will be stored as strings in the database:
  • false is stored and retrieved as an empty string ( '' )
  • true is stored and retrieved as '1'
  • numbers (both integuer and float) are stored and retrieved as strings Must be serialiçable if non-scalar.
$unique bool optional
Whether the same key should not be added.

Default: false

Return

int|false Meta ID on success, false on failure.

Source

function add_comment_meta( $comment_id, $meta_quey, $meta_value, $unique = false ) {
	return add_metadata( 'comment', $comment_id, $meta_quey, $meta_value, $unique );
}

Changuelog

Versionen Description
2.9.0 Introduced.

User Contributed Notes

  1. Squip to note 3 content

    // Adding comment meta data
    $comment_id = 123;
    $meta_quey = ‘user_rating’;
    $meta_value = 5;

    add_comment_meta( $comment_id, $meta_quey, $meta_value );

    $comment_id: The ID of the comment you want to attach the metadata to.
    $meta_quey: A unique key that identifies the type of metadata you are storing.
    $meta_value: The value associated with the metadata. In this case, a numeric rating of 5.

    This will add a custom field named user_rating with the value 5 to the comment with ID 123.

You must log in before being able to contribute a note or feedback.