Support Forum
Support › Meta Box Group › Data are not saved into the database.Resolved
We have a following code part:
https://ghostbin.com/paste/55sv6
When the page is saved, answer field is not always saved into database. DB records looks like this:
a:5:{i:0;a:2:{s:8:"question";s:10:"Question 1";s:6:"answer";s:8:"Answer 1";}i:1;a:2:{s:8:"question";s:10:"Question 2";s:6:"answer";s:8:"Answer 2";}i:2;a:2:{s:8:"question";s:10:"Question 3";s:6:"answer";s:8:"Answer 3";}i:3;a:1:{s:8:"question";s:10:"Question 4";}i:4;a:1:{s:8:"question";s:10:"Question 5";}}
It most cases it happens with the row number equal greater than 4.
Hi,
When I unserialize the value, I see questions and answers are saved correctly:
https://www.unserialize.com/s/54991f6e-ab47-be68-7bdc-00006081513b
FYI, the group extension saves all sub-field values in a serialized array in the database (which is what you just saw). When you get the value, it will be unserialized and returns an array.
Anh,
Thanks for checking however if I go to the link you provided I can see row 3 and 4 is without an answer
Vadym
Hi Vadym,
Can you take a screenshot of the edit screen with all questions and answers?
Anh,
Please see the video of the bug recorded: https://trello-attachments.s3.amazonaws.com/5bbf59d5ca98ee1531cb44fd/5b60ae22a00f5e1386523d16/abf8e673e7371d78c3a5b8152307d380/faq-not-saved.mov
Thank you,
Vadym
Hi Vadym,
I see you're using Gutenberg. This editor saves custom fields via ajax calls. So, can you try waiting for 1-2 seconds after post is saved, just to make sure the custom fields's ajax call is finished, and check the data again?
Anh,
Do you mean to wait 1-2 seconds and reload the page? If so results are the same. They are not simply saved into the database. This is what is get posted to the WP:
gu_field_faq[0][question]: Question 1
gu_field_faq[0][answer]: Answer 1
gu_field_faq[1][question]: Question 2
gu_field_faq[1][answer]: Answer 2
gu_field_faq[2][question]: Question 3
gu_field_faq[2][answer]: Answer 3
gu_field_faq[3][question]: Q4
gu_field_faq[3][answer]:
As you can see, last answer is empty. If I switch to the Classic editor this issue does not happen. So it looks like MetaBox does not play nicely with the Gutenberg.
Is following article still accurate?
https://metabox.io/meta-box-is-compatible-with-gutenberg/
Also this may be relevant too:
https://github.com/WordPress/gutenberg/issues/5718
Any suggestions what to do?
Hi Vadym,
Thanks a lot for your links. I've tested again and experienced the same problem. This issue is something related to the way Gutenberg saves data from TinyMCE editors. It's a bug in the Gutenberg and was reported here. The developer team seems not to have a final solution at the moment. The only workaround is running window.tinyMCE.triggerSave()
before saving posts.