Automattic / custom-metadata

A WordPress plugin that provides an easy way to add custom fields to your object types (post, pages, custom post types, users)
https://wordpress.org/plugins/custom-metadata/
193 stars 46 forks source link

How can I update cloneable field values? #138

Open MrJoshFisher opened 2 years ago

MrJoshFisher commented 2 years ago

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.