admin管理员组

文章数量:1394054

I have an array of values to store in the post meta, my post data looks like below JSON representation

[
  {
    "field_1": "value 1",
  },

  {
    "field_1": "value 2",
  },

  {
    "field_1": "value 3",
  },


]

And each item can have multiple keys like field_2, field_3 other than field_1, i have converted the JSON to array, and looped through each item and store in meta data by calling add_post_meta() function, but the problem arises when i want to have a duplicate in this list like this

    [
      {
        "field_1": "value 1",
      },
      {
        "field_1": "value 1",
      },
   ]

since i need the ability to update each item, i need to find a way to make the meta to properly update duplicate values, because update_post_meta take previous value and current value so if i update field_1 to any value, the second item might be updated to same value of first item, how to handle this problem?

本文标签: Can we have duplicate key pair values in post meta data