Created
January 20, 2014 21:55
-
-
Save bjorn2404/8529984 to your computer and use it in GitHub Desktop.
WordPress - convert Gravity Form date format string to a string without extra characters when submitting to a post type. In my situation I wanted to go from yyyy/mm/dd to yyyymmdd for Advanced Custom Fields compatibility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Filter GF date and convert to compatible ACF date string | |
* $form['id'] is the id of the Gravity Form and $post_data['post_custom_fields']['event_date'] is the custom field | |
*/ | |
add_filter('gform_post_data', 'custom_update_gf_date', 10, 3); | |
function custom_update_gf_date($post_data, $form){ | |
if($form['id'] == 2 && $post_data['post_custom_fields']['event_date']){ | |
$post_data['post_custom_fields']['event_date'] = preg_replace('/[^0-9,.]/', '', $post_data['post_custom_fields']['event_date']); | |
} | |
return $post_data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment