Last active
August 29, 2015 13:55
-
-
Save mustardBees/8720914 to your computer and use it in GitHub Desktop.
Hook into Gravity Forms after form submission in order to save latitude/longitude in the format expected by the CMB Field Type: Google Maps plugin.
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 | |
/** | |
* Save latitude/longitude for display in a CMB field | |
* | |
* @author Phil Wylie | |
* @link http://link.from.pw/1ejMnDr | |
*/ | |
function pw_save_latitude_longitude( $entry, $form ) { | |
$latitude = $entry[3]; // where 3 is the field ID for latitude | |
$longitude = $entry[4]; // where 4 is the field ID for longitude | |
$location = array( | |
'latitude' => $latitude, | |
'longitude' => $longitude | |
); | |
update_post_meta( $entry['post_id'], 'location', $location ); // location is your CMB field ID | |
} | |
add_action( 'gform_after_submission_1', 'pw_save_latitude_longitude', 10, 2 ); // where 1 is the form ID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment