Automattic / Automattic/custom-metadata
How can I update cloneable field values?
- Dominant language
- PHP
- Stars
- 190
- Forks
- 46
- Avg merge
- 46m
- Merged PRs (30d)
- 15
Description
Hello,
I'm having an issue with trying to update the values of a cloneable field, for instance,
Retrieving the value as follows
`$emails = get_post_meta(123, 'memo_category-103');`
`print_r($emails);` as you'd expect returns
`Array ( [0] => test2@test2.com [1] => test@test.com )`
I can array push to add a new value:
```
array_push($emails, 'test3@test3.com');
Array ( [0] => test2@test2.com [1] => test@test.com [2] => test3@test3.com );
```
But when I save it for example
```
$emails = array('test2@test2.com', 'test@test.com', ' test3@test3.com');
update_post_meta(123, 'memo_category-103', $emails);
```
I get this
`Array ( [0] => Array ( [0] => test2@test2.com [1] => test@test.com [2] => test3@test3.com ) [1] => Array ( [0] => test2@test2.com [1] => test@test.com [2] => test3@test3.com ) )`
I've tried several different ways to try and rectify this but it doesn't work, I would love to switch to a different meta field plugin but unfortunately, I can't as there are thousands of posts stored using this so I'm having to try my best to rectify it, any help would be greatly appreciated.
Or if anyone else has a solution it too would be greatly appreciated.
Contributor guide
Research direction
Reproduce the nested-array result using get_post_meta(123, 'memo_category-103') and update_post_meta(...) with the email values shown. Inspect the plugin's cloneable-field handling and metadata write path; done means updating the existing field preserves the intended flat values without duplicating the array.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, wordpress
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100