Gutenberg: getEditedPostAttribute("meta") in Custom Post Type Returns Undefined

Created on 13 Aug 2019  路  3Comments  路  Source: WordPress/gutenberg

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:

  1. register a posttype, PHP:
    register_post_type('my_posttype',array( 'labels' => array( 'name' => 'My PostType', ), 'public' => true, 'show_in_rest'=>true, ));
  2. register a post meta, PHP:
    register_post_meta('my_posttype','meta_name',array( 'show_in_rest' => true, 'single' => true, 'type' => 'string', ));
  3. Open My PostType / write new post
  4. Browser Press F12 show console
  5. type JS:
    wp.data.select( 'core/editor' ).getEditedPostAttribute('meta')
  6. Press enter
  7. return undefined

Expected behavior
JS : wp.data.select( 'core/editor' ).getEditedPostAttribute('meta')
Should returns a Object like:
{ meta_name: '' }

Screenshots
1

Desktop (please complete the following information):

  • OS: Windows
  • Browser Firefox
  • Version 68.0.1

Smartphone (please complete the following information):

  • Device:
  • OS:
  • Browser
  • Version

Additional context

  • Please add the version of Gutenberg you are using in the description.
    6.2.0
  • To report a security issue, please visit the WordPress HackerOne program: https://hackerone.com/wordpress.
Needs Technical Feedback REST API Interaction [Package] Data

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, ));

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings