Skip Navigation

[Resolved] How to programmatically add value to multiple value email field ?

This support ticket is created 3 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by himanshuS 3 years, 2 months ago.

Assisted by: Waqar.

Author
Posts
#2221849

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.

#2221953

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

#2222613

Waqar, I appreciate the help. My issue is resolved now. Thank you!