0

I added like/dislike buttons on the comments section of the blog posts on the site and aimed for them to update the meta_value according to the meta_key under wp_commentmeta. However, when any of buttons is clicked, the meta_value of all comments under that post is updated. How can I fix it?

<a href="<?php echo add_query_arg('comment_action', 'like'); ?>">
    <i class="fa fa-thumbs-up" style="font-size: 1.3em; margin-right: 10px; color: #4E64DD;"></i></a>

<a href="<?php echo add_query_arg('comment_action', 'dislike'); ?>">
    <i class="fa fa-thumbs-down" style="font-size: 1.3em; margin-right: 1.2rem; color: #4E64DD;"></i></a>

       <?php    
            switch($_GET['comment_action']){
                case 'like':
                    $like_count = get_comment_meta($comment->comment_ID, 'begeni_skor', true);
                    if($like_count >= 1) {
                        $like_count++;
                    }else {
                        $like_count = 1;
                    }
                    update_comment_meta($comment->comment_ID, 'begeni_skor', $like_count);
                    get_the_permalink();
                break;
                    
                case 'dislike':
                    $dislike_count = get_comment_meta($comment->comment_ID, 'begenmeme_skor', true);
                    if($dislike_count >= 1) {
                        $dislike_count++;
                    }else {
                        $dislike_count = 1;
                    }
                    update_comment_meta($comment->comment_ID, 'begenmeme_skor', $dislike_count);
                    get_the_permalink();
                break;
            }
    ?>  

        

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.