update_comment_meta

Update comment meta field based on comment ID.

Description

(int|bool) update_comment_meta( (int) $comment_id, (string) $meta_key, (mixed) $meta_value, (string) $prev_value = '' ); 

Use the $prev_value parameter to differentiate between meta fields with the same key and comment ID.

If the meta field for the comment does not exist, it will be added.

Returns (int|bool)

Meta ID if the key didn't exist, true on successful update, false on failure.

Parameters (4)

0. $comment_id (int)
The comment id.
1. $meta_key (string)
The meta key.
2. $meta_value (mixed)
The meta value.
3. $prev_value — Optional. (string) => ''
Previous value to check before removing.

Usage

  1. if ( !function_exists( 'update_comment_meta' ) ) { 
  2. require_once ABSPATH . WPINC . '/comment.php'; 
  3.  
  4. // The comment id. 
  5. $comment_id = -1; 
  6.  
  7. // The meta key. 
  8. $meta_key = ''; 
  9.  
  10. // The meta value. 
  11. $meta_value = null; 
  12.  
  13. // Optional. Previous value to check before removing. 
  14. $prev_value = ''; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = update_comment_meta($comment_id, $meta_key, $meta_value, $prev_value); 
  18.  

Defined (1)

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

/wp-includes/comment.php  
  1. function update_comment_meta($comment_id, $meta_key, $meta_value, $prev_value = '') { 
  2. return update_metadata('comment', $comment_id, $meta_key, $meta_value, $prev_value);