public
Created

Gravity Forms - UNIX Timestamp

  • Download Gist
gistfile1.aw
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
<?php
 
add_action( 'gform_post_submission_1', 'be_event_timestamp', 10, 2 );
/**
* Create a UNIX timestamp based on Gform date fields
* @author Bill Erickson
* @link http://www.billerickson.net/code/gravity-forms-unix-timestamp
* @link http://www.gravityhelp.com/documentation/page/Gform_post_submission
*
* 'gform_post_submission' applies to all forms, append form ID to specify
*
* @param array $entry
* @param array $form
* @return array
*/
function be_event_timestamp( $entry, $form ) {
$start_date = get_post_meta( $entry['post_id'], 'be_event_start_date', true );
if( $start_date ) {
$timestamp = strtotime( $start_date );
update_post_meta( $entry['post_id'], 'be_event_start_date_unix', $timestamp );
}
$end_date = get_post_meta( $entry['post_id'], 'be_event_end_date', true );
if( $end_date ) {
$timestamp = strtotime( $end_date );
update_post_meta( $entry['post_id'], 'be_event_end_date_unix', $timestamp );
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.