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

Meta fields undefined after reuse commit #25078

Closed
iandunn opened this issue Sep 4, 2020 · 0 comments · Fixed by #25083
Closed

Meta fields undefined after reuse commit #25078

iandunn opened this issue Sep 4, 2020 · 0 comments · Fixed by #25083
Labels
[Package] Data /packages/data [Type] Bug An existing feature does not function as intended

Comments

@iandunn
Copy link
Member

iandunn commented Sep 4, 2020

After bfbcc92 (#19498, #15114), fetching a REST API field like meta._wp_page_template no longer works.

Reproduction Steps

  1. Edit a page and add a template to it. You may need to switch to a theme that has templates, like TwentyTwenty.
  2. Make that meta field available in the REST API. Add this to an mu-plugin:
    register_post_meta(
    	'page',
    	'_wp_page_template',
    	array(
    		'show_in_rest' => true,
    	)
    );
  3. Call the following from any block's Edit function:
    function test() {
    	const args = {
    		_fields: [
    			'id',
    			'slug',
    			'meta._wp_page_template',
    		],
    	};
    
    	const test = useSelect(
    		( select ) => {
    			return select( 'core' ).getEntityRecords( 'postType', 'page', args );
    		},
    		[]
    	);
    
    	console.log( null !== test ? test[ 0 ][ 'meta' ] : test );
    }
  4. Add that block to a post/page.
  5. git checkout bfbcc92a207dd6813967bf1eff667f0a1e1bcc56~1 and reload. You should see the meta data available in the console.
  6. git checkout bfbcc92a207dd6813967bf1eff667f0a1e1bcc56, and reload. You should only see null in the console.

cc @youknowriad , @aduth , @mcsf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Data /packages/data [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant