2013-01-07 90 views
1

從前端,我想讓作者拿起他的職位的最佳評論/答案。我很接近,但還沒有。每次點擊按鈕,該帖子的所有評論都被選爲最佳(這是錯誤的)。它應該只爲每個帖子選擇一條評論。WordPress的 - 讓後作者選擇最好的評論(前端)

在function.php我有以下幾點:

add_action ('comment_post', 'add_comment_field', 1); 
function add_comment_field($comment_id) { 
    add_comment_meta($comment_id, 'bestanswer', 'no', false); 
} 

在comment.php我有以下幾點:

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

    } 
?> 

的思考?建議?任何幫助將不勝感激。

回答

1

我通過添加每條評論的鏈接解決了這個問題。鏈接轉到顯示該評論的頁面。在這個頁面上,作者然後選擇評論作爲最佳答案。現在評論元僅保存用於特定評論。我知道是一個額外的步驟,但我更喜歡這種方法,因爲作者必須確保這是他想要選擇的評論。一旦評論被選擇爲最佳,作者不能改變它。

相關問題