Reputation: 8070
How to update the post meta with array in wordpress.
For Example I tried this one to
$mail_list_array1 = get_post_meta($_POST['productid'], 'notify_emailsse');
$mail_list_array[] = $_POST['notifyaddress'];
$mail_list_arrays = array_merge($mail_list_array1, $mail_list_array);
update_post_meta($_POST['productid'], "notify_emailsse", $mail_list_arrays);
Now It returning the output as this way
array(1) {
[0]=> array(2) {
[0]=> array(2) {
[0]=> string(0) ""
[1]=> string(10) "t43tsdtret"
} [1]=> string(21) "weyriweyriynbdkxhfkds"
}
}
But I want this way
array(1) {
[0] => 'Email 1',
[1]=>'Email 2',
....}
How can i achieve that using post meta of wordpress. The reason what i am achieving for example: If the user enter his email in the text field and i want to save the email in a one meta, same thing some other user also enter his email then that email should append as in common meta of wordpress. Shortly means saving multiple values into the same meta key.
Any Suggestion would be great.
Thanks, vicky
Upvotes: 0
Views: 1060
Reputation: 1554
I'm not sure about your purpose, but easiest will be to implode() arrays and then serialize() your post meta. After reading post meta do the opposite, to have data as an array: unserialize() and explode()
Upvotes: 1