Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
Wordpress

WordPress: Fix the Block Editor Autosave Dropping Custom Fields

- 28.11.26 - ErcanOPAK

📝 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.

— WordPress Admin

Related posts:

WordPress: Fix a Multisite Network Where New Subsites Keep Inheriting the Wrong Default Theme

WordPress: Fix a Multisite Network Where New Subsites Keep Inheriting the Wrong Default Theme

WordPress: Fix a Multisite Subsite's Media Uploads Silently Writing Into the Main Site's Upload Fold...

WordPress: Fix a Multisite Subsite's Media Uploads Silently Writing Into the Main Site's Upload Fold...

WP-Cron Runs on User Requests (Not Real Cron)

WP-Cron Runs on User Requests (Not Real Cron)

Views: 7
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

SQL Server: Fix a Natively Compiled Procedure Rejecting a Hint
C#: Fix a Static Lambda Still Capturing the Outer Instance

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Read

  1. 01How to make theater mode the default for Youtube 1,079 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 997 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 996 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 views
  5. 05How to select distinct rows in a datatable in C# 868 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 671 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 631 views
  8. 08Average of all values in a column that are not zero in SQL 584 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 562 views
Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
Back to top
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com