Note to admins: I have been trawling every possible resource for this but cannot find a good answer for modern WordPress, so please don't mark this as a duplicate of ("insert some answer from 2012 here"). I have seen the article by John Blackbourn but it is from a completely different era of WordPress.
I am using a meta block to store custom meta against a custom post type as per the recommended WordPress modern approach in the developer guide. It works perfectly, but the meta block content is not stored/recalled with the revisions, ie. when I load up an older revision, the post meta from the post at that time is not recalled, only the HTML block content like paragraphs, images etc.
The developer guide says nothing about making the meta compatible with revisions (at least not in that article about meta boxes), so I imagine this needs to be done manually – but I can't see how.
When I review the revisions in the Revisions UI, I can see the meta block raw JSON there delimiting the meta block, but there is no content. It looks like this in the post revisions UI (the block is registered as cwf/event-meta
):
<!-- wp:cwf/event-meta /-->
I am just wondering if anyone knows what best practice for getting custom meta to be compatible with post revisions is now that the calls to update meta are done via REST?
And how can we see the changes to the meta in the revision screens?
Any help gladly received as I am finding it hard to get up-to-date information on the best way to do this.
save
function does return something (a non-empty string)? Maybe you can share the code? Or am I not understanding the issue here?<!-- wp:cwf/event-meta /-->
" - yes and that's how it's supposed to look like, because thesave
function doesn't need to be defined, returns anull
, or that such meta blocks don't return anything that will be stored as part of the post content.wp-admin/revision.php
, right? And "so I imagine this needs to be done manually" - yes, I'm afraid so, because I don't think Gutenberg has implemented (post) meta revisions - there are functions to get post revisions, but not to update them via Gutenberg without creating a custom REST API endpoint to handle the updating.