Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getEditedPostAttribute("meta") in Custom Post Type Returns Undefined #17018

Closed
conanliuhuan opened this issue Aug 13, 2019 · 3 comments
Closed
Labels
Needs Technical Feedback Needs testing from a developer perspective. [Package] Data /packages/data REST API Interaction Related to REST API

Comments

@conanliuhuan
Copy link

conanliuhuan commented Aug 13, 2019

Describe the bug
I registered a custom posttype and set it "show in rest"
JS:wp.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.
@conanliuhuan
Copy link
Author

This BUG affects Custom Post Type Gutenberg Sidebar:
图片

@swissspidy swissspidy added [Package] Data /packages/data Needs Technical Feedback Needs testing from a developer perspective. REST API Interaction Related to REST API labels Aug 13, 2019
@conanliuhuan
Copy link
Author

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

@raquelmv
Copy link

THANK YOU, took me 1 day of frustration to get here @conanliuhuan

erikjoling pushed a commit to erikjoling/gutenberg that referenced this issue Mar 19, 2020
Added extra clarification for when registering post meta for the editor doesn't seem to work for custom post types.

See WordPress#17018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Technical Feedback Needs testing from a developer perspective. [Package] Data /packages/data REST API Interaction Related to REST API
Projects
None yet
Development

No branches or pull requests

3 participants