title: How to update post meta on wordpress with AJAX
body: <p>I have the following code:</p>
  
  <pre><code>&lt;form method='post'&gt;
  &lt;input type='submit' name='bid' value='Licitar'&gt;
  </code></pre>
  
  <p>When the user clicks the submit button, I want to update the WordPress post meta, in order to change the actual bid value.</p>
  
  <p>I'd also like to update, without reloading the page, the following div:</p>
  
  <pre><code>&lt;div class='vehicle-value-box'&gt;".auctionplugin_get_latest_bid($post-&gt;ID).",00€&lt;/div&gt;
  </code></pre>
  
  <p>How can I do both? I have troubles understanding how to capture the $_POST value and use it to do the things above mentioned. Where do I need to put the PHP processing code and include it in WordPress ajax core?</p>
  
  <p>EDIT:</p>
  
  <p>Now my code looks like on page.php (INSIDE THE LOOP, and it is all being "echoed" with PHP):</p>
  
  <pre><code>&lt;div id='vehicle-value-box".$post-&gt;ID."'&gt;".get_post_meta(get_the_ID(),'start_price', true).",00€&lt;/div&gt;
   (...)
  &lt;div class='vehicle-auction-box'&gt;
  &lt;script&gt;
  jQuery('input[type=submit]').click(function(e) {
      e.preventDefault();
      jQuery.ajax({
           type: 'POST',
           url: ajaxurl,
           data: 'action=newbid&amp;id=".$post-&gt;ID."',
           success: function(msg){
      jQuery('#vehicle-value-box".$post-&gt;ID."').html(msg+',00€');
      }
  });
  &lt;/script&gt;
  &lt;div&gt;
  &lt;form method='post'&gt;
      &lt;input type='submit' name='bid".$post-&gt;ID."' value='Licitar' class='bidvalue'&gt;
  </code></pre>
  
  <p>And my functions.php:</p>
  
  <pre><code>add_action('wp_ajax_newbid', 'newbid_ajax');
  function newbid_ajax() {
      $post_id = $_POST['id'];
      $mybid = get_post_meta($post_id, 'start_price', true);
      $mybid = $mybid + 100;
      update_post_meta($post_id,'start_price',$mybid);
      die($mybid);
  }
  </code></pre>