update_comment_meta()更新一个评论的meta自定义附加信息

目录

描述

The function update_comment_meta() updates the value of an existing comment meta key for the specified comment.

This may be used in place of the add_comment_meta() function. The first thing this function will do is make sure that $meta_key already exists on $comment_id. If it does not it will be added.

update_comment_meta() 描述

用法

 <?php update_comment_meta$comment_id$meta_key$meta_value$prev_value ); ?> 

update_comment_meta() 用法

参数

$comment_id

(integer) (必填) The ID of the comment which contains the field you will edit.

默认值: None

$meta_key

(string) (必填) The key of the custom field you will edit.

默认值: None

$meta_value

(mixed) (必填) The new value of the custom field. A passed array will be serialized into a string.

默认值: None

$prev_value

(mixed) (可选) The old value of the custom field you wish to change. This is to differentiate between several fields with the same key. If omitted, and there are multiple rows for this post and meta key, all meta values will be updated.

默认值: None

update_comment_meta() 参数

返回值

(boolean

False on failure, true if success.

update_comment_meta() 返回值

示例

Default Usage

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
<?php update_comment_meta( 3416, 'my_key', 'Brad' ); ?>

update_comment_meta() 示例

注意

历史

添加于 版本: 2.9.0

update_comment_meta() 历史

源文件

update_comment_meta() 函数的代码位于 wp-includes/comment.php

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Update comment meta field based on comment ID.
 *
 * 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.
 *
 * @since 2.9.0
 * @link https://codex.wordpress.org/Function_Reference/update_comment_meta
 *
 * @param int $comment_id Comment ID.
 * @param string $meta_key Metadata key.
 * @param mixed $meta_value Metadata value.
 * @param mixed $prev_value Optional. Previous value to check before removing.
 * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure.
 */
function update_comment_meta($comment_id, $meta_key, $meta_value, $prev_value = '') {
	return update_metadata('comment', $comment_id, $meta_key, $meta_value, $prev_value);
}

update_comment_meta() 源文件

相关