add_comment_meta

Add meta data field to a comment.

Description

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

Returns (int|bool)

Meta ID on success, false on failure.

Parameters (4)

0. $comment_id (int)
The comment id.
1. $meta_key (string)
Metadata name.
2. $meta_value (mixed)
The meta value.
3. $unique — Optional. (constant) => false
Optional, default is false. Whether the same key should not be added.

Usage

  1. if ( !function_exists( 'add_comment_meta' ) ) { 
  2. require_once ABSPATH . WPINC . '/comment.php'; 
  3.  
  4. // The comment id. 
  5. $comment_id = -1; 
  6.  
  7. // Metadata name. 
  8. $meta_key = ''; 
  9.  
  10. // The meta value. 
  11. $meta_value = null; 
  12.  
  13. // Optional, default is false. Whether the same key should not be added. 
  14. $unique = false; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = add_comment_meta($comment_id, $meta_key, $meta_value, $unique); 
  18.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/comment.php  
  1. function add_comment_meta($comment_id, $meta_key, $meta_value, $unique = false) { 
  2. return add_metadata('comment', $comment_id, $meta_key, $meta_value, $unique);