Home Forums General Issues update_field not working onclick


update_field not working onclick

  • 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 :-

    // Query the custom post type to display
        $args = array('post_type' => 'books');
        $query = new WP_Query( $args );
        while ( $query->have_posts() ) : 
                    if ( has_post_thumbnail() ): 
      <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.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘update_field not working onclick’ is closed to new replies.