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');
}
}
?>
的思考?建議?任何幫助將不勝感激。