I have a scenario where I want to transfer value from the child post custom field to the intermediary post custom field.
The field is a multiple value custom field which I m passing as an array to the new field but this does not work. What is the right way to insert values in multiple value toolset fields?
Field data in child post - hidden link
//get member emails from the post itself and store it in intermediary post
$group_member_emails = get_post_meta($post_id, 'wcpf-group-member-emails',); // a numeric array is returned
update_post_meta($intermediary_workspace_id,'wpcf-group-member-emails', $group_member_emails);
No data is added to the intermediary post custom field.
Hi,
This question is not related to Toolset fields specifically, but, the general usage of WordPress post meta functions and PHP.
If you'll check the documentation of "update_post_meta" and "add_post_meta", you'll note that they support a single value and not an array ( in your code "$group_member_emails" is an array):
https://developer.wordpress.org/reference/functions/update_post_meta/
https://developer.wordpress.org/reference/functions/add_post_meta/
In this case, you'll need to use a 'foreach' loop and the 'add_post_meta' function, because the 'update_post_meta' will keep updating the single custom field record and you need to add each email as a separate record:
foreach( $group_member_emails as $group_member_email ) {
add_post_meta( $intermediary_workspace_id, 'wpcf-group-member-emails', $group_member_email );
}
regards,
Waqar
Waqar, I appreciate the help. My issue is resolved now. Thank you!