Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using a custom post type for a portfolio. I have a few option in there, bring saved by update_post_meta(), it seems to work fine, but then out of the blue (within the hour), the data deletes its self. I have looked in the DB and all custom metadata values are empty.

I'm a little stumped really.

Here's the code that's saving one of the options.

function update_colour_palette(){
    global $post;
    $color = get_post_custom($post->ID);
 $palette = $color["palette"][0];
    update_post_meta($post->ID, "palette", $_POST["palette"], $palette);
}

Any help, tips & tricks would be useful.

share|improve this question
2  
@PaulAllenDavis: How do you trigger update_colous_palette()? Because the post saves revisions multiple times via Ajax while the editor is open, you should check for this and not update the post meta if this is the case. –  Jan Fabry Dec 16 '10 at 11:51
add comment

2 Answers 2

up vote 3 down vote accepted

I've been using this for a while to solve exactly your issue, I think I got it from the codex somewhere. But it works.

// verify if this is an auto save routine. 
// If it is our form has not been submitted, so we dont want to do anything
    if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
        return $post_id;
share|improve this answer
    
Seems to have fixed the issue for me. (Sorry for the 8 months delay, just had the same problem again) –  PaulAdamDavis Aug 16 '11 at 11:33
add comment

I assume this is in a post edit/ post save action, in which case you should add checks for user level and a nonce in there. If you don't then this can be called in all sorts of places where the post values don't exist.

share|improve this answer
    
Yes, you're correct. I'll add that soon. –  PaulAdamDavis Dec 16 '10 at 12:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.