📝 Fix the Block Editor Autosave Dropping Custom Fields
Gutenberg’s autosave runs entirely through the REST API’s posts endpoint, and any custom field added the classic way – register_meta() without show_in_rest, or a meta box rendered purely with add_meta_box() – is invisible to that REST payload. A normal full save still works, because WordPress still fires save_post with the classic $_POST data outside of REST entirely, but autosave’s draft revision, and the “restore from autosave” recovery prompt after a crash, only ever reconstruct whatever the REST response described – so a value you just typed into a non-REST-registered custom field silently isn’t there the moment you ever restore from an autosaved revision.
🔎 The Problem
// functions.php - classic meta registration, not REST-visible
register_meta("post", "event_location", array(
"type" => "string",
"single" => true,
// no "show_in_rest" => missing entirely
));
// Browser crash while editing a post with an unsaved "event_location" value
// -> WordPress offers: "This post has been updated. Would you like to
// restore the autosave?"
// -> Restoring: title/content recovered correctly, event_location field
// is blank, because it was never part of the autosaved REST payload.
✅ Fix: Register Custom Fields for REST
- Add ‘show_in_rest’ => true (or a full REST schema array if the field needs type validation) to every register_meta() call backing a field you want Gutenberg’s autosave and revisions to actually include.
- For a meta box still rendered with the older add_meta_box() API, add a matching register_post_meta() call with show_in_rest so the value is exposed through REST even though the editing UI itself stays in a classic meta box.
- After changing meta registration, reload the editor and confirm the field now appears in the REST response at /wp-json/wp/v2/posts/<id>?context=edit before trusting that autosave will carry it.
🚨 Why This Is Dangerous
Because the classic full save still works perfectly, this gap only ever shows up at the worst moment – after a crash, a closed tab, or a lost connection, when the only version of the post left to recover from is the one autosave silently wrote without that field.
If a custom field isn’t registered for REST, Gutenberg doesn’t know it exists – and autosave can only protect what it can actually see.




