add_comment_meta( int $comment_id, string $meta_key, mixed $meta_value, bool $unique = false )
将元数据字段添加到评论中。
描述
参数
- $comment_id
- (int)
(Required)
评论 ID - $meta_key
- (string)
(Required)
键名 - $meta_value
- (mixed)
(Required)
键值 - $unique
- (bool)
(Optional)
是否应该添加相同的键。Default value: false
返回值
(int|bool) 成功返回元数据的 ID,失败返回 false。
源代码
File: 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);
}
更新日志
Version | 描述 |
---|---|
2.9.0 | Introduced. |
相关函数
Uses
- wp-includes/meta.php:add_metadata()
Used By
- wp-includes/comment.php:wp_spam_comment()
- wp-includes/comment.php:wp_insert_comment()
- wp-includes/comment.php:wp_trash_comment()
基本用法
为每个新注释添加自定义的值。
<?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' );
?>
你可能对这些文章感兴趣:
- wordpress函数floated_admin_avatar()用法示例
- wordpress函数category_description()用法示例
- wordpress函数attachment_submitbox_metadata()用法示例
- wordpress函数attachment_id3_data_meta_box()用法示例
- wordpress函数atom_site_icon()用法示例
- wordpress函数atom_enclosure()用法示例
- wordpress函数array_replace_recursive()用法示例
- wordpress函数apply_filters_ref_array()用法示例
- wordpress函数apply_filters_deprecated()用法示例
- wordpress函数apache_mod_loaded()用法示例
- wordpress函数antispambot()用法示例
- wordpress函数allow_subdomain_install()用法示例
- wordpress函数allow_subdirectory_install()用法示例
- wordpress函数allowed_tags()用法示例
如有疑问,请前往问答中心反馈!
反馈