Like & Dislike functionality using JavaScript
Question
I want to add Like & Dislike functionality into my custom post type, called game
.
I have placed like and dislike icon links in my post footer.
Desired Behaviour:
When a user clicks the like icon, I want to check if (s)he already voted for it and if not then create or update post like count meta key inside the post meta and same goes for the user meta.
Problem:
The problem is when a user clicks the like button, I have to handle it inside the JavaScript but I am not sure how to call
set_post_meta($post->ID)
or
update_post_meta($post->ID)
from JavaScript.
Loop:
<?php while ( $r->have_posts() ) : $r->the_post();?>
<?php if (has_post_thumbnail()): ?>
<?php the_post_thumbnail('small'); ?>
<?php endif;?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<div class="game-footer">
<div class="like-dislike-btn-div">
<i class="game-footer-like-btn fa fa-thumbs-o-up">0</i>
<i class="game-footer-dislike-btn fa fa-thumbs-o-down">0</i>
</div>
</div>
<?php endwhile; ?>
0
post-meta, user-meta
4 years
2020-03-27T12:51:25-05:00
2020-03-27T12:51:25-05:00 0 Answers
125 views
0
Leave an answer