JSON Data getting reformated on Save/Edit

Support General JSON Data getting reformated on Save/Edit

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #8632
    GreatNews.LifeGreatNews.Life
    Participant

    I have a field that is for display purposes only... i have posts getting imported into wordpress automatically and applying meta values like this on import:

    add_post_meta($wpid, 'gnl_galleries_album_images', $image_list);

    $image_list being a php array.

    On import its being stored in the database like this:

    a:60:{s:7:"G9K4ZnD";a:2:{s:5:"thumb";s:185: .........

    Now I have a Metabox.io Text box that is read only on the post that just displays that JSON data for reference.

    If i edit the post and hit save, the record in the meta table changes to something like this:

    {"G9K4ZnD":{"thumb":"https:/...... etc.

    How do i have the Metabox.io maintain the original format and not change the JSON structure?

    #8633
    GreatNews.LifeGreatNews.Life
    Participant

    testing, if i remove the field from "display" the field maintains it structure in the database.. which i guess i can just remove it from showing.. but its nice to see for a reference on importing script.

    I guess, is it possible to have a field show that is display only and not updated on save. or if it does run the update on the field, keep the same format.

    #8646
    Anh TranAnh Tran
    Keymaster

    Hello,

    Now I have a Metabox.io Text box that is read only on the post that just displays that JSON data for reference.

    Where does the JSON data come from? I see you store an array in the post meta, which is a serialized array.

    #8650
    GreatNews.LifeGreatNews.Life
    Participant

    its just data from an old system that is actually just a php array that gets assigned to the post using add_post_meta ... because i dont think you have your own version of add_post_meta correct?

    Then im just using metabox.io to display only

    #8660
    Anh TranAnh Tran
    Keymaster

    But when you imported, you already used add_post_meta() which converts the array into serialized string. So it's not JSON anymore. I'm quite confused about that.

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