Question

I was having the problem with WordPress autosave not sending custom field data, and found this entry on SO:

Wordpress add_meta_box() weirdness

The approved answer works, but is it not just preventing any autosave from happening by returning early? Isn't the same as disabling autosave completely? If so, wouldn't it be better to do so in the proper way instead of letting it try to autosave just to prevent it?

The only exception I could see is if one checked for a post-type before checking for autosave so that you only disabled autosave for certain post types.

I'm going to be disabling autosave completely, but was wondering what you guys thought.

EDIT: I'm not having problems with the autosave anymore. This question is to discuss the merits of the solutions that I mentioned above.

Additionally, I can't see how this would be a feature of WordPress, and would assume that autosave should be changed to include all post data. No?

Was it helpful?

Solution

The code in the linked answer does not disable autosave, it only stops a custom save function executing when autosaving. This is necessary because the Wordpress autosave system does not support post meta data (custom fields), either in the Javascript which collates the post data or in the PHP which creates and restores revisions.

OTHER TIPS

I've used the following for Custom Fields I've created and it's worked fine.

<?php
// Save Fields
add_action('save_post', 'save_details');

function save_details(){
 if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) 
    return $post_id;
 global $post;
 update_post_meta($post->ID, "event_featuring", $_POST["event_featuring"]);
 update_post_meta($post->ID, "event_time", $_POST["event_time"]);
 update_post_meta($post->ID, "event_date", $_POST["event_date"]);
 update_post_meta($post->ID, "event_end_date", $_POST["event_end_date"]);
 update_post_meta($post->ID, "event_location", $_POST["event_location"]);
 update_post_meta($post->ID, "bhs_event", $_POST["bhs_event"]);
}
?>

FYI, the solution posted here http://wordpress.org/support/topic/custom-post-type-information-disappearing worked for me and I think is much more elegant.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top