POC: Use Block bindings API with existing post_meta
Opened this issue · 0 comments
Similar to #330 I wanted to validate my ideas on data-migration.
Today: The new Block bindings API connected to existing post_meta.
This should help migrating the existing shortcodes, which use some special template tags like {{duration}}
to display post_meta. I did bind the post_meta field of remark
to a new core block variation, and it worked really well.
Ressources
Steps I took
- Update to WP 6.5 beta 1
- Change
register_post_type
arguments ofwp_theatre_prod
to support `'custom-fields' - Change
register_post_meta
to include'show_in_rest'
following the Testing Instructions - Just add the markup into the editor
<!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"core/post-meta","args":{"key":"remark"}}}}} -->
<p>Paragraph</p>
<!-- /wp:paragraph -->
This worked really well.
To make this a little easier to recognize for the editor I created a simple block-variation of the paragraph block to hold the markup I added by hand in the step before. This block variation even allowed me to define a custom name and icon, which was nice.
Block variations could be one way to go to properly migrate into the new era. You can give it a try and have a look through the code at https://github.com/figuren-theater/theater-production-blocks/tree/feature/wpt-shortcode-to-query-block
some findings to feed back to the gutenberg contributors
- Transforming a paragraph into a headline erases all relevant block attributes, which is a known issue
- adding the attributes to
registerBlockVariation()
fails, because 'metadata' is undefined; 🐛 maybe this is no properly registered attribute