gpt4 book ai didi

wordpress - 如何在管理员评论部分显示评论的元字段值?

转载 作者:行者123 更新时间:2023-12-04 22:46:14 25 4
gpt4 key购买 nike

我在 wordpress 评论表单中为用户年龄添加了一个额外的字段。
我以这种方式添加了该字段:

add_filter('comment_form_default_fields','add_comment_fields');
function add_comment_fields($fields) {
$fields['location'] = '<p class="comment-form-location"><label for="location">' . __( Location ) . '</label>' .
'<input id="location" name="location" type="text" size="30" /></p>';

return $fields;

}

而且我还通过使用“comment_post”操作将元值保存在评论元表中。
现在我必须在管理员评论部分显示这个评论元值。我怎样才能做到这一点 ?

最佳答案

试试下面的代码,希望你能在管理部分看到你的额外字段(这里我使用年龄作为元键)。

add_action( 'add_meta_boxes_comment', 'comment_add_meta_box' );
function comment_add_meta_box()
{
add_meta_box( 'my-comment-title', __( 'Your field title' ), 'comment_meta_box_age', 'comment', 'normal', 'high' );
}

function comment_meta_box_age( $comment )
{
$title = get_comment_meta( $comment->comment_ID, 'age', true );

?>
<p>
<label for="age"><?php _e( 'Your label Name' ); ?></label>;
<input type="text" name="age" value="<?php echo esc_attr( $title ); ?>" class="widefat" />
</p>
<?php
}
add_action( 'edit_comment', 'comment_edit_function' );
function comment_edit_function( $comment_id )
{
if( isset( $_POST['age'] ) )
update_comment_meta( $comment_id, 'age', esc_attr( $_POST['age'] ) );
}

关于wordpress - 如何在管理员评论部分显示评论的元字段值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24417651/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com