Skip to content

Instantly share code, notes, and snippets.

@bjorn2404
Created January 20, 2014 21:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjorn2404/8529984 to your computer and use it in GitHub Desktop.
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
<?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