add_comment_meta()给一个评论添加meta自定义附加信息

目录

描述

Add meta data field to a comment.

add_comment_meta() 描述

用法

<?php add_comment_meta$comment_id$meta_key$meta_value$unique ); ?>

add_comment_meta() 用法

参数

$comment_id

(int) (必填) Comment ID.

默认值: None

$meta_key

(string) (必填) Metadata name.

默认值: None

$meta_value

(mixed) (必填) Metadata value.

默认值: None

$unique

(boolean) (可选) Optional, default is false. Whether the same key should not be added.

默认值: false

add_comment_meta() 参数

返回值

(bool

False for failure. True for success.

add_comment_meta() 返回值

示例

Add a custom posted value to every new comment

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

<?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' );
?>

add_comment_meta() 示例

历史

添加于 版本: 2.9

add_comment_meta() 历史

源文件

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

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Add meta data field to a comment.
 *
 * @since 2.9.0
 * @link https://codex.wordpress.org/Function_Reference/add_comment_meta
 *
 * @param int $comment_id Comment ID.
 * @param string $meta_key Metadata name.
 * @param mixed $meta_value Metadata value.
 * @param bool $unique Optional, default is false. Whether the same key should not be added.
 * @return int|bool Meta ID on success, false on failure.
 */
function add_comment_meta($comment_id, $meta_key, $meta_value, $unique = false) {
	return add_metadata('comment', $comment_id, $meta_key, $meta_value, $unique);
}

add_comment_meta() 源文件

相关