Saving Dates with Gravity Forms & Custom Post Types
-
Hi,
I’m in the process of debugging my site before a launch and I’ve come across an interesting issue. I have a Gravity Form for patient registration and it captures four different dates, which are then stored as fields in a custom post type, however the CPT’s are powered by wp-types and for some reason the two plugins handle dates differently. At the suggestion of a forum post from wp-types website I have been using this code for the after submission GForms hook:
add_action( 'gform_after_submission', 'gf_to_types_date', 10, 2 ); function gf_to_types_date( $entry, $form ) { foreach($form["fields"] as $field){ if($field["inputType"] == "date") { $custom_field_name = $field['postCustomFieldName']; var_dump($custom_field_name); $gf_date = get_post_meta( $entry['post_id'], $custom_field_name, true ); if( $gf_date ) { $types_date = strtotime( $gf_date ); update_post_meta( $entry['post_id'], $custom_field_name, $types_date ); var_dump($entry['post_id']); var_dump($custom_field_name); var_dump($types_date); } } } }
This works well in one of two ways, if just the first date is filled in (this is a compulsory field) it will save that one, if they are all filled in it will save them all, but if another combination of the fields is completed (the other three being optional) it will save none of them correctly even though the dump from the code shows each is being figured out correctly.
I’m at a loss to explain what is going wrong, can anyone shed some light on what may be the issue with the code please?
My best guess is it’s something to do with the loop’s logic but I’m not sure.
Regards
- The topic ‘Saving Dates with Gravity Forms & Custom Post Types’ is closed to new replies.