I need some help with saving my meta data from a post. On the editpage I have the following input fields

<input type="text" name="data[color][]" value="red"/>
<input type="text" name="data[color][]" value="blue"/>
<input type="text" name="data[size][]" value="small"/>
<input type="text" name="data[width][]" value="30"/>
<input type="text" name="data[width][]" value="32"/>

If I click on save / update post the array is saved as

    color => array("blue"),
    size => array("small"),
    width => array("32"),

It has to be saved as

    color => array("red", "blue"),
    size => array("small"),
    width => array("30", "32"),

Wordpress get only the last items.

How can I fixed this?

  • See wordpress.stackexchange.com/questions/220483/…
    – WebElaine
    Commented Jan 19, 2022 at 14:30
  • Hi WebElaine this does not fix my issue :( I think the issue is in the serialize function from Wordpress. Is it possible to disable the serialize for these inputs?
    – Liekeee
    Commented Jan 19, 2022 at 23:52
  • No, postmeta arrays are always serialized. It might be worth looking into a simpler postmeta structure - i.e. save the color as one piece of postmeta, the size as another, the width as another.
    – WebElaine
    Commented Jan 20, 2022 at 15:00


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.