Wordpress-让帖子作者选择最佳评论(前端)

Wordpress-让帖子作者选择最佳评论(前端),wordpress,comments,meta,author,Wordpress,Comments,Meta,Author,在前端,我想让作者从他的文章中获得最好的评论/答案。我很接近,但还没到那里。每次我点击按钮,该帖子的所有评论都被选为最佳(这是错误的)。每个帖子只能选择一条评论 在function.php中,我有以下内容: add_action ('comment_post', 'add_comment_field', 1); function add_comment_field($comment_id) { add_comment_meta($comment_id, 'bestanswer', 'no

在前端,我想让作者从他的文章中获得最好的评论/答案。我很接近,但还没到那里。每次我点击按钮,该帖子的所有评论都被选为最佳(这是错误的)。每个帖子只能选择一条评论

在function.php中,我有以下内容:

add_action ('comment_post', 'add_comment_field', 1);
function add_comment_field($comment_id) {
    add_comment_meta($comment_id, 'bestanswer', 'no', false);
}
<?php
    $current_author = get_the_author_meta('nickname');
    global $current_user; get_currentuserinfo();
    if ($current_user->nickname == $current_author) {
?>
<?php
    $my_post_meta = get_comment_meta($comment->comment_ID, 'bestanswer', true);
    if ( $my_post_meta == 'yes' ) {
            echo '<h4>Best answer</h4>';
        } else {
        ?>
        <form method="post" action="" id="bestanswer-<?php comment_ID() ?>">
            <input type="submit" name="confirm" value="Best Answer" />
        </form>
        <?php   

        if (isset($_POST['confirm'])) {
            update_comment_meta($comment->comment_ID, 'bestanswer', 'yes');
        }

    }
?>
在comment.php中,我有以下内容:

add_action ('comment_post', 'add_comment_field', 1);
function add_comment_field($comment_id) {
    add_comment_meta($comment_id, 'bestanswer', 'no', false);
}
<?php
    $current_author = get_the_author_meta('nickname');
    global $current_user; get_currentuserinfo();
    if ($current_user->nickname == $current_author) {
?>
<?php
    $my_post_meta = get_comment_meta($comment->comment_ID, 'bestanswer', true);
    if ( $my_post_meta == 'yes' ) {
            echo '<h4>Best answer</h4>';
        } else {
        ?>
        <form method="post" action="" id="bestanswer-<?php comment_ID() ?>">
            <input type="submit" name="confirm" value="Best Answer" />
        </form>
        <?php   

        if (isset($_POST['confirm'])) {
            update_comment_meta($comment->comment_ID, 'bestanswer', 'yes');
        }

    }
?>


我通过给每条评论添加一个链接来解决这个问题。该链接将转到显示该注释的页面。在这一页上,作者选择评论作为最佳答案。现在,注释元仅为该特定注释保存。我知道这是一个额外的步骤,但我更喜欢这种方法,因为作者必须确保这是他想要选择的评论。一旦该评论被选为最佳,作者就无法更改它。

我通过为每个评论添加一个链接来解决这个问题。该链接将转到显示该注释的页面。在这一页上,作者选择评论作为最佳答案。现在,注释元仅为该特定注释保存。我知道这是一个额外的步骤,但我更喜欢这种方法,因为作者必须确保这是他想要选择的评论。一旦该评论被选为最佳评论,作者将无法对其进行更改