WordPress开发函数add_comment_meta(),向注释添加元数据字段。
add_comment_meta( int $comment_id, string $meta_key, mixed $meta_value, bool $unique = false )
$comment_id
(int) (必需) 评论ID。
$meta_key
(string) (必需) 元数据名称。
$meta_value
(mixed) (必需) 元数据的值。如果是非标量,则必须是可序列化的。
$unique
(bool) (可选) 是否不应该添加相同的键。
默认值:假
(int|false) Meta ID成功,失败为false。
文件: wp-includes/comment.php
function add_comment_meta( $comment_id, $meta_key, $meta_value, $unique = false ) {
return add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique );
}
(由Codex - 5年前贡献)
基本的例子
为每个新评论添加一个自定义的发布值
<?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' );
?>