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.

So I've been coding a theme and I'm working on a custom post type. When I edit a custom post and save the changes (click Update) everything is ok.

But - I noticed that when I leave the Edit page open for a while and come back to it a few minutes later and try to refresh, that dialog "Stay On Page/Leave Page" pops up and if I choose "leave page" all of the content from the custom meta boxes is lost. Only the title remains.

I'm guessing this has something to do with the way that I'm saving the data from the custom meta boxes, so here it is:

add_action('admin_init', 'init_portfolio_meta_boxes');

function init_portfolio_meta_boxes() {
    add_meta_box('short_description', 'Short Description', 'short_description_meta', 'portfolio', 'normal');
}

function short_description_meta() {
    global $post;
    $custom = get_post_custom($post->ID);
    $short_description = $custom['short_description'][0];
    ?>
        <textarea name="short_description" style="width: 200px; height: 100px;"><?php echo $short_description; ?></textarea>
    <?php
}

add_action('save_post', 'save_details');
function save_details() {
    global $post;
    update_post_meta($post->ID, 'short_description', $_POST['short_description']);
}

That's the entire code for one of the meta boxes, I followed a tutorial to get to it.

share|improve this question
    
Don't sure, but did you try save_details($post_id)? like described here codex.wordpress.org/Plugin_API/Action_Reference/save_post –  Alexey May 8 '12 at 12:13
    
have you look in DB if your 'short_description' is saved correctly (in postmeta table) ? if yes, you must look at get_post_meta codex.wordpress.org/Function_Reference/get_post_meta –  Tribalpixel May 8 '12 at 12:37

1 Answer 1

This is because save_details is not checking if its an autosave routine:

add_action('save_post', 'save_details');
function save_details() {
    global $post;
    // verify this is not an auto save routine. 
    if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return;
    update_post_meta($post->ID, 'short_description', $_POST['short_description']);
}
share|improve this answer

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.