Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter jbucks

    (@jbucks)

    OK, think I’ve got it. I found this link which describes exactly the problem I was having:
    https://stackoverflow.com/questions/2539951/wordpress-add-meta-box-weirdness

    So I changed the save_details() function from my code above by checking if wordpress is auto-saving, and so far it’s working:

    function save_details() {
      global $post;
    
      $post_id = $post->ID;
    
      // to prevent metadata or custom fields from disappearing...
      if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
        return $post_id;
    
      update_post_meta($post_id, "land_cost", $_POST["land_cost"]);
    
    }
    Thread Starter jbucks

    (@jbucks)

    Nevermind, it didn’t work. The problem is occurring again – I waited a few minutes, and suddenly the ‘cost’ field disappears from the most recent land listing entry on the home page, along with the ‘cost’ value in the meta box (in WP admin) for that post…

    this is really frustrating…

    Thread Starter jbucks

    (@jbucks)

    Problem solved, but I don’t understand why. This function (from the code above)…

    function land_cost(){
    	  global $post;
    	  $custom = get_post_custom($post->ID);
    	  $land_cost = $custom["land_cost"][0];
    
    	  echo '<label>For rent or free:</label>
    	  <input name="land_cost" value="' . $land_cost . '" />';
    
    }

    …needed to be replaced by the following code:

    function land_cost(){
      global $post;
      $custom = get_post_custom($post->ID);
      $land_cost = $custom["land_cost"][0];
      ?>
      <label>Cost:</label>
      <input name="land_cost" value="<?php echo $land_cost; ?>" />
      <?php
    }

    It would be great if someone could explain to me why this worked…

Viewing 3 replies - 1 through 3 (of 3 total)