Problem: I have a Form that includes a custom field that accepts multiple values and another custom field that only accepts a single value. If the single value doesn't exist in the multiple value field, I would like to add it using cred_save_data.
Solution: You should get_post_meta on the repeating field, to access an array of values it currently stores. Something like this:
$itms = get_post_meta( $post_id, 'wpcf-all-items', false );
Now $itms is an array of instance values:
Array ( [0] => instance 1 [1] => instance 2 [2] => instance 3 )
Then you can use PHP's in_array function to check to see if the new value already exists. If not, add it. If so, skip adding it.
Relevant Documentation:
https://www.php.net/manual/en/function.in-array.php
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 |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 2 replies, has 2 voices.
Last updated by 5 years, 3 months ago.
Assisted by: Christian Cox.