how to call “set_post_meta()” function from Javascript?
I want to add Post Like functionality in my custom post type (game). I have placed clickable like and dislike icons game-footer-like-btn
in my post footer both on single.php and on post archive. Now what i want is that when a user press the like icon(clickable) i want to check if he/she 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. The problem is when a user press the like button i have to handle it inside the JS but i am not sure how to call set_post_meta($post->ID)
or update_post_meta($post->ID)
from JS. Or if there is any other way around ? following is my code for the custom post loop.
`
<?php while ( $r->have_posts() ) : $r->the_post();?>
<div class="col-md-3 game-card-outer">
<div class="game-card">
<?php if (has_post_thumbnail()): ?>
<a href="<?php the_permalink();?>"><?php the_post_thumbnail('small', array('class' => 'aligncenter')); ?></a>
<?php endif;?>
<a class="latest_games_widget_post_title" 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>
</div>
</div>
<?php endwhile; ?>`
Leave an answer