-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
[Feature Request] Save to post meta with block data #244
Comments
Hey. I don't quite understand the reason. Currently data saved in the Meta automatically by Gutenberg, and you can output this attribute using function We don't need to duplicate data inside the block, you just work with Meta directly. |
I will make a video and explain. |
Sorry to interject. @hj-collab do you mean that you want the attribute (such as SKU in your example) to save to the post_meta of the currently post being currently edited by that block? |
Tick this option for any of the field you want, then go to editor for a post, type something in that field and refresh after 10 seconds. You will lose the changes. Saving to gutenberg block data keep the changes as autosave even if you close the tab, pc crashed, etc.
How to solve the problem? You give an option to allow a block to be saved in both - block_deta and post_meta. Reason: I want to save in post_meta in database but I also want the benefits of block_data (autosave, proper undo and post_revisions) I hope this is clear. Let me know if more info is required. |
Oh I totally understand. It probably doesn't undo properly and doesn't save post_revisions properly because there's no markup changing in the block at all. A simple solution would be to add a "revision" attribute that would simply be filled with the unix timestamp at the same rate as a normal block attributes save cycle. It would trigger post revisions, but there would still be problems with undo. The other solution, as you said, would be to save to both block attributes and post meta, but prioritize post meta if it's found... though that would run the risk of creating conflicts with other blocks unless there's proper block-to-meta mapping - or left willingly naïve and leave the responsibility to the developer to manage this. |
@davidwebca Also autosave. Autosave is important when you are working with lots of field and lots of data to enter. It should read from block data only else autosave, post revisions and undo won't work and write to block data and meta. I need meta because I have areas where getting meta data is easier then parsing block data. This also gives easy way to move out of block in case you face some limitations and can use the meta data with anything else. |
Understand, but I don't like the idea to save duplicates here (block attribute + meta field). We are using the standard Meta block attribute and I see that it is deprecated now https://developer.wordpress.org/block-editor/reference-guides/block-api/block-attributes/#meta-source-deprecated. I will recheck this feature in the next plugin updates. |
I have just changed the deprecated meta attributes and used I have googled and looks like WordPress doesn't autosave meta at all, it is by design. If you have any ideas on how to improve the autosave function properly, I want to look at a solution. Saving both block attribute and meta is a bad idea, because:
|
@nk-o There is an open request at wp/gutenberg GitHub, and they have not been working on this issue for a long time. Since this requirement is limited to some users, we can wait until we have a proper solution, most likely from the core WP team. |
I had raised a request regarding this before but I was not clear about it. I am okay if this feature request comes in the upcoming paid version. I had written my own custom block as I wanted to save data into post_meta as well as block attributres. I feel it will not be difficult to add. This is how I do it.
I write to attributes as well as meta on onChange. Check screenshot:-
Reason is that If I only read and save to meta then I won't enjoy auto save, post revisions and ability to use full editor area and not just small size sidebar panel. Check screenshot:-
@nk-o Please take a look and include this in your paid version.
The text was updated successfully, but these errors were encountered: