WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/add comment meta

Description

Add meta data field (custom field) to a comment.

Usage

<?php add_comment_meta$comment_id$meta_key$meta_value$unique ); ?>

Parameters

$comment_id
(int) (required) Comment ID.
Default: None
$meta_key
(string) (required) Meta data name. It is the key of the meta data field which should be added.
Default: None
$meta_value
(mixed) (required) Meta data value.
Default: None
$unique
(boolean) (optional) Whether or not you want the key to stay unique. When set to true, the meta data field will not be added if the given key already exists among meta data fields of the specified comment.
Default: false

Return Values

(bool) 
False for failure. True for success.

Examples

Add a custom posted value to every new comment

<?php
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' );
?>

Change Log

Since: 2.9

Source File

add_comment_meta() is located in wp-includes/comment.php

Related

Comment Meta Functions: add_comment_meta(), get_comment_meta(), update_comment_meta(), delete_comment_meta()

See also index of Function Reference and index of Template Tags.