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

This topic contains 8 replies, has 2 voices, and was last updated by  Anh Tran 1 week, 2 days ago.

  • Creator
    Topic
  • #11633

    guwebservices
    Participant

    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.

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

    Anh Tran
    Keymaster

    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.

    #11649

    guwebservices
    Participant

    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

    #11658

    Anh Tran
    Keymaster

    Hi Vadym,

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

    #11665

    guwebservices
    Participant
    #11684

    Anh Tran
    Keymaster

    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?

    #11726

    guwebservices
    Participant

    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?

    • Vadym
    #11749

    Anh Tran
    Keymaster

    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.

    #12524

    Anh Tran
    Keymaster

    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.