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

Dispatching editPost action does not save/update existing meta value #12544

Closed
garciaalvaro opened this issue Dec 3, 2018 · 8 comments
Closed
Labels
Needs Testing Needs further testing to be confirmed. [Package] Editor /packages/editor

Comments

@garciaalvaro
Copy link

Describe the bug
Register the following meta:

function qqq_register_meta() {
	register_post_meta( 'post', 'test_meta', array(
		'show_in_rest' => true,
		'single'       => true,
	) );
}
add_action( 'init', 'qqq_register_meta' );

In a new post editor page, try to update the meta from the console:

wp.data.dispatch("core/editor").editPost({meta:{test_meta:"a_value"}});

Then publish the post. This will save the meta with no problem (notice the post was new so there was no value assigned to the meta key).

Refresh the just published post editor page from the browser and call editPost again with a different value:

wp.data.dispatch("core/editor").editPost({meta:{test_meta:"a_different_value"}});

Publish the changes.

The meta does not update and still has the previous value.

Thanks.

Version

  • WordPress 4.9.8
  • Gutenberg 4.6.1
@swissspidy
Copy link
Member

I think this was fixed in #12331.

Can you try this with the current master build of Gutenberg?

See also #12289 (of which this one is probably a duplicate).

@swissspidy swissspidy added [Status] Needs More Info Follow-up required in order to be actionable. [Package] Editor /packages/editor labels Dec 3, 2018
@garciaalvaro
Copy link
Author

Could you point me on how to zip the production version of the branch so I can test?
I tried also merging the meta returned by getEditedPostAttribute to the meta object, but the issue is still the same (I thought that was fixed in #12331).

@swissspidy
Copy link
Member

You can run npm run build and afterwards npm run package-plugin to generate a gutenberg.zip file that you can upload to your site.

This might take a while, so I went ahead and built a ZIP for you: gutenberg.zip

@garciaalvaro
Copy link
Author

Thanks, I tested with the zip you sent and the behaviour is the same.

@swissspidy swissspidy added Needs Testing Needs further testing to be confirmed. and removed [Status] Needs More Info Follow-up required in order to be actionable. labels Dec 3, 2018
@garciaalvaro
Copy link
Author

Seems like it works right, not sure if the issue was related to the server. I'll close the issue and comment again if I figure out what was causing the problem. Thanks.

@minimal2
Copy link

I noticed that when custom fields are displayed they overwrite dispatched meta value.

Tested on WordPress 5.2.2

@mikebhart
Copy link

Disabling the custom fields from been shown solves this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Testing Needs further testing to be confirmed. [Package] Editor /packages/editor
Projects
None yet
Development

No branches or pull requests

5 participants
@minimal2 @swissspidy @garciaalvaro @mikebhart and others