Title: Saving Dates with Gravity Forms &amp; Custom Post Types
Last modified: August 20, 2016

---

# Saving Dates with Gravity Forms & Custom Post Types

 *  [theslink2000](https://wordpress.org/support/users/theslink2000/)
 * (@theslink2000)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/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.

## Tags

 * [custom post type](https://wordpress.org/support/topic-tag/custom-post-type/)
 * [date](https://wordpress.org/support/topic-tag/date/)
 * [get_post_meta](https://wordpress.org/support/topic-tag/get_post_meta/)
 * [update_post_meta](https://wordpress.org/support/topic-tag/update_post_meta/)
 * [wp-types](https://wordpress.org/support/topic-tag/wp-types/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 0 replies
 * 1 participant
 * Last reply from: [theslink2000](https://wordpress.org/support/users/theslink2000/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/saving-dates-with-gravity-forms-custom-post-types/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
