I’ve had this problem since I first delved into the crazy world of custom post types in WordPress. Every time I would create a custom post type with its own custom meta fields like for example a Movies custom post type with custom fields of year and director, something along those lines. I’d fill out the main body of text for the page and then fill out the custom fields, which worked fine when I saved and previewed it. However I noticed that if I left my WordPress editing screen open after a little while the custom meta fields would empty themselves, and only the main body of text in the editor would remain.
I figured this had something to do with the auto save in WordPress and did a little research, it turns out that this little snippet of code can save your day.
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
I’m not entirely sure how this code works but I figure it asks WordPress if it’s auto saving, to kindly run the save function as well, which it does.
So a custom field save function in your functions.php would look something like this originally.
function save_domain(){
global $post;
update_post_meta($post->ID, "domain", $_POST["domain"]);
}
Would become something like…
function save_domain(){
global $post;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
update_post_meta($post->ID, "domain", $_POST["domain"]);
}
And hey presto, no more disappearing custom fields. Hopefully this helps