Function Reference/add comment meta
Description
Add meta data 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) Metadata name.
- Default: None
- $meta_value
- (mixed) (required) Metadata value.
- Default: None
- $unique
- (boolean) (optional) Optional, default is false. Whether the same key should not be added.
- Default: false
Return Values
- (bool)
- False for failure. True for success.
Examples
Add a custom posted value to every new comments
<?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