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

Function Reference/add comment meta


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


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


(int) (required) Comment ID.
Default: None
(string) (required) Meta data name. It is the key of the meta data field which should be added.
Default: None
(mixed) (required) Meta data value.
Default: None
(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

False for failure. True for success.


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

Change Log

Since: 2.9

Source File

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


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.