WordPress.org

Ready to get started?Download WordPress

Codex

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

Function Reference/add comment meta

Contents

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 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.