add_comment_meta( int $comment_id, string $meta_key, mixed $meta_value, bool $unique = false )

Add meta data field to a comment.



(int) (Required) Comment ID.


(string) (Required) Metadata name.


(mixed) (Required) Metadata value. Must be serializable if non-scalar.


(bool) (Optional) Whether the same key should not be added.

Default value: false

Top ↑


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

Top ↑


File: wp-includes/comment.php

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

Top ↑


Version Description
2.9.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Codex

    Basic Example

    Add a custom posted value to every new comment

    function add_custom_comment_field( $comment_id ) {
       add_comment_meta( $comment_id, 'my_custom_comment_field', $_POST['my_custom_comment_field'] );
    add_action( 'comment_post', 'add_custom_comment_field' );

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