Problem: I would like to automatically copy an address custom field value into another textarea custom field when the post is saved.
Solution: It depends on whether the post is saved with CRED or if the post is saved in wp-admin. If CRED, you can use the cred_save_data hook:
add_action('cred_save_data', 'copy_location_to_multiline_field',10,2); function copy_location_to_multiline_field($post_id, $form_data) { // if a specific form if ($form_data['id']==12345) { if (isset($_POST['wpcf-location'])) { // add it to saved post meta update_post_meta($post_id, 'wpcf-multiline', $_POST['wpcf-location']); } } }
Replace 12345 with the CRED form ID, and replace 'wpcf-location' and 'wpcf-multiline' with the correct field slugs. Add the 'wpcf-' prefix to the slug shown in wp-admin for each field.
If they are created in wp-admin, you can use the save_post hook:
add_action( 'save_post', 'copy_location_to_multiline_field_admin', 100, 3 ); function copy_location_to_multiline_field_admin( $post_id, $post, $update ) { if ( $post->post_status == 'publish' && $post->post_type == 'cptslug' ) { $location = get_post_meta( $post_id, 'wpcf-location', true); update_post_meta( $post_id, 'wpcf-multiline', $location ); } }
Replace 'cptslug' with the slug of the post type where you have your address field, and replace 'wpcf-location' and 'wpcf-multiline' with the correct field slugs. Add the 'wpcf-' prefix to the slug shown in wp-admin for each field.
Relevant Documentation: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://codex.wordpress.org/Plugin_API/Action_Reference/save_post
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.
Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.
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)
Dieses Thema enthält 2 Antworten, hat 2 Stimmen.
Zuletzt aktualisiert von vor 7 Jahren.
Assistiert von: Christian Cox.