Describe the bug
I registered a custom posttype and set it "show in rest"
JS锛歸p.data.select( 'core/editor' ).getEditedPostAttribute('meta')
this returns undefied, it shoud always returns an Object.
To reproduce
Steps to reproduce the behavior:
register_post_type('my_posttype',array(
'labels' => array(
'name' => 'My PostType',
),
'public' => true,
'show_in_rest'=>true,
));
register_post_meta('my_posttype','meta_name',array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
));
wp.data.select( 'core/editor' ).getEditedPostAttribute('meta')
Expected behavior
JS : wp.data.select( 'core/editor' ).getEditedPostAttribute('meta')
Should returns a Object like:
{
meta_name: ''
}
Screenshots
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context
This BUG affects Custom Post Type Gutenberg Sidebar:
If custom post type wants to get meta in gutenberg, it have to support custom-fields when it register.
register_post_type('my_posttype',array(
'labels' => array(
'name' => 'My PostType',
),
'public' => true,
'supports' => [
'title',
'editor',
'custom-fields',
],
'show_in_rest'=>true,
));
THANK YOU, took me 1 day of frustration to get here @conanliuhuan
Most helpful comment
If custom post type wants to get meta in gutenberg, it have to support custom-fields when it register.
register_post_type('my_posttype',array( 'labels' => array( 'name' => 'My PostType', ), 'public' => true, 'supports' => [ 'title', 'editor', 'custom-fields', ], 'show_in_rest'=>true, ));