The meta value is read when the block loads and assigned to the block attribute. Changes to the block will update the attribute and when the post saves the value will save to the meta. So, as far as I understood, there is no need to actually save anything in the registerBlockType
js function. The block only saves to the meta so in the front end nothing will be rendered (unlike non-meta blocks).
So in your case:
add_action( 'init', function() {
register_post_type( 'game', [
'label' => 'Games',
'public' => true,
'supports' => [ 'editor', 'custom-fields' ],
'show_in_rest' => true,
] );
register_post_meta( 'game', 'logo', [
'single' => true,
'show_in_rest' => true,
'description' => 'A meta key associated with a string meta value.',
'type' => 'string'
] );
} );
Notice that I used register_post_meta
which was included in version 4.9.8 and allows to use the post type name (“game” in this case). As noticed by @LABCAT in the other answer using register_meta
requires the type to be “post” even for custom post types.
Then in the JavaScript file:
registerBlockType( 'game-post/meta', {
//...
save: () => null,
});
I hope this helps.