Custom Fields
Support Meta Box Group Data are not saved into the database.

  • Creator
  • #11633

    We have a following code part:

    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.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Author
  • #11639
    Anh Tran


    When I unserialize the value, I see questions and answers are saved correctly:

    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.



    Thanks for checking however if I go to the link you provided I can see row 3 and 4 is without an answer


    Anh Tran

    Hi Vadym,

    Can you take a screenshot of the edit screen with all questions and answers?

    Anh Tran

    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?



    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

    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?

    Also this may be relevant too:

    Any suggestions what to do?

    • Vadym
    Anh Tran

    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.

    Anh Tran

    Hi Vadym,

    I've just added a fix on Github. Please check it. Thanks.

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.