3

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.

4
  • "but there is no content" - so your block's save function does return something (a non-empty string)? Maybe you can share the code? Or am I not understanding the issue here?
    – Sally CJ
    Commented Jul 13, 2022 at 10:15
  • @SallyCJ - Meta blocks don't have a save function. See this: developer.wordpress.org/block-editor/how-to-guides/metabox This is partially why I am confused - there seems to be something internal showing the delimiter for the meta block but it just looks like this: <!-- wp:cwf/event-meta /--> Where cwf is my namespace and event-meta is the name of the block. Commented Jul 13, 2022 at 10:53
  • "it just looks like this: <!-- wp:cwf/event-meta /-->" - yes and that's how it's supposed to look like, because the save function doesn't need to be defined, returns a null, or that such meta blocks don't return anything that will be stored as part of the post content.
    – Sally CJ
    Commented Jul 15, 2022 at 0:23
  • "the post revisions UI" - you meant, at 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.
    – Sally CJ
    Commented Jul 15, 2022 at 0:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.