update_field没有工作onclick

时间:2015-03-12 15:16:56

标签: javascript php advanced-custom-fields

我有一个名为count的自定义字段。当我点击帖子图片的投票按钮时,我正在尝试增加并将其值保存到帖子中。但是,它不会更新自定义字段的值,也不会在页面上更新......没有任何反应

     <?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="myvote($post_id,$newcount)">Vote</button><?php echo " ".$oldcount;?></div>

        <?php endif; endwhile; ?>

   <script language="Java Script" type="text/javascript">
    function myvote($pid,$tempcount) {
    $.ajax({
        type: "POST",
        url: "<?php bloginfo('template_directory'); ?>/voteajax.php",
        data: {action:'call_this',pid:$pid,tempcount:$tempcount},
        cache: false,
        success: function(html){
            $("body").append(html);
         }
       });
    };
    </script>

voteajax.php

<?php
   if($_POST['action'] == 'call_this') {
   update_field('field_5501', $_POST['tempcount'],$_POST['pid']; 
   }
?>

0 个答案:

没有答案