单击按钮 只有最后一个帖子会更改


onclicking button only the last post changes

无论我单击哪个btn,都只会更改最后一个帖子的计数...如何更改相应的计数

    <?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() ): 
                $postid = get_the_ID();
                $oldcount=get_field('count');
                $newcount=$oldcount+1;                              
    ?>
        <form action="#" method="post">
        <div><?php the_post_thumbnail('thumbnail'); ?><input id="<?php echo $postid;?>" type="submit" name="submit" value="Vote" /><?php echo " ".$oldcount;?></div>
        </form>
    <?php endif; endwhile; ?>
<?php 
    if (isset($_POST['submit'])) { 
    $ID = $_GET['id'];
    echo $ID;
    echo " button clicked";    
    update_field('field_55014a',$newcount,$ID); 
    }
?>

您通过 POST 提交表单,但尝试使用$_GET['id']这不符合<input id="<?php echo $postid;?>">

更改表单,使其提交帖子 ID:

 <?php
 // THIS PORTION OF THE CODE MUST COME FIRST!!!!!
 if (isset($_POST['submit'])) { 
     $id = $_POST['id'];
     $newcount = // query your database, get the vote count then add one.
     update_field('field_55014a',$newcount,$id); 
     header('Location: '. $_SERVER['PHP_SELF']);
     exit();
 }
 $args = array('post_type' => 'books');
 $query = new WP_Query( $args );
 while ( $query->have_posts() ) {
     $query->the_post();
     if ( has_post_thumbnail() ) {
         $postid = get_the_ID();
         $votecout =get_field('count');
     ?>
         <form action="" method="POST">
             <div>
             <?php the_post_thumbnail('thumbnail'); ?>
             <input type="hidden" value="<?php echo $postid; ?>" name="id" />
             <input type="submit" name="submit" value="Vote" />
             <?php echo $oldcount; ?>
             </div>
         </form>
    <?php
    } // close if
} // close while