I have a custom field called count. I am trying to increase and save its value to a post when a vote button is clicked for the image of the post. However, it doesn’t update the value of custom field nor does it update on the page…nothing happens
my page template is as follows :-
<?php
// Query the custom post type to display
$args = array('post_type' => 'books');
$query = new WP_Query( $args );
while ( $query->have_posts() ) :
$query->the_post();
if ( has_post_thumbnail() ):
$oldcount=get_field('count');
$newcount=$oldcount+1;
?>
<div><?php the_post_thumbnail('thumbnail'); ?><button onclick="<?php update_field('my_field_key', $newcount, $post_id); ?>">Vote</button><?php echo " ".$oldcount;?></div>
<?php endif; endwhile; ?>
Hi @littledevil,
Thanks for the post.
I am not sure the type of custom field that you have set for the ‘count’ but this should be set to a number field.