Problem: I would like to use the cred_save_data API to set the value of a custom field that is not managed by Toolset.
Solution: You can use the cred_save_data hook to add or change custom field information after the post is saved, even if the fields are not managed by Types. Types custom field slugs begin with "wpcf-" in the database, but other non-Toolset fields do not have this prefix. So if your custom field slug is "field-slug", then the code will look like this:
add_action('cred_save_data', 'nonts_custom_field_value_action',10,2); function nonts_custom_field_value_action($post_id, $form_data) { $forms = array( 12345 ); // if a specific form if (in_array($form_data['id'], $forms)) { update_post_meta( $post_id, 'field-slug', 'field value' ); } }
Change 12345 to match the numeric ID of this Form, change field-slug to match the slug of the custom field, and change field value to be the value you want to store in the custom field.
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://codex.wordpress.org/Function_Reference/update_post_meta
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 6 years, 4 months ago.
Assisted by: Christian Cox.