-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Block attributes don't update custom meta fields #12794
Comments
Also I can't display the value on the frontend. I can see it on backend but on the frontend it is empty. Any ideas? |
You need to use |
I have already added register_post_meta() but it doesn't work. I don't even get the values on the frontend. The meta data is available in the REST API but it is not updated. |
Would you mind sharing your whole block registration code here then so we can verify this? |
Sure. Here it is: index.php file:
and basic-info-block.js:
Thanks in advance. |
Do you need something else? I also have this callback function to return the value:
|
I think I found the problem here. I had to remove the save_post action from the old code as it replaced the new value with old one. However, it seems that I still can't display the value in the frontend. The callback function works great in the backend but on the frontend it is empty. For example, if I add:
then I only get Short Info: in the frontend and the $atts['event_short_info'] is empty. |
That is to be expected. When you store attributes in post meta, they're not part of You have to retrieve them using |
@izachros I am having the same problem as you. How did you fix it in the end? Unfortunately, I have no clue which function you mean with "save_post"?
I am also able to save my meta value when creating a new post (custom post type), however, the update fails and sets the initial value/changes nothing. Some other people seem to have the same problem and its a reported bug: |
@bracketsberlin I recommend you to create a new issue with your request instead of commenting on old, closed issues. Otherwise nobody will really notice your question. Also, you need to share all your block's code (including how you configured attributes), otherwise it's impossible to know what is going wrong. Please also note that you'll need to use
|
First, you have to register your custom meta fields using a function like this:
Then, you have to change your code to:
Also, make sure that you use add_meta_boxes action as this:
Hope this will help you fix the problem. |
@izachros Thank you very much for your help. The Or do I get something wrong and you also propose your solution when it comes to working with Gutenberg blocks? As @swissspidy suggested, it probably makes more sense to work on the new issue. Thanks for your help, guys. |
Yeah that |
Describe the bug
I created a block that gets the values of some custom meta fields and adds them to block attributes. However, when I try to save the new value of a field it seems that the editor saves the value but when I refresh the page the block displays the old value. It actually didn't save the new value to meta field.
I added support for 'custom-fields' and I use the following code for the block:
el( InspectorControls, {}, el( TextControl, { label: 'Meta Field', value: props.attributes.meta_field, onChange: ( value ) => { props.setAttributes( { meta_field: value } ); }, } ) )
Also, i have one more field that doesn't get the value from a meta field and it seems to work great as it saves the new value (not to a meta field).
Does anyone have a solution for this? Thanks in advance!
The text was updated successfully, but these errors were encountered: