forked from jessedmatlock/code-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Google map using ACF and Geo Mashups
43 lines (22 loc) · 1.28 KB
/
Google map using ACF and Geo Mashups
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// http://support.advancedcustomfields.com/forums/topic/acf-and-geo-mashup-integration/
// http://wpquestions.com/question/showLoggedIn/id/10778
// How to combine multiple locations onto one Google map using ACF and Geo Mashups
//
// This is how you integrate ACF’s Google Maps field with Geo Mashup.
add_action('save_post', 'wpq_acf_gmap');
function wpq_acf_gmap($post_id) {
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
if( !isset($_POST['acf_nonce'], $_POST['fields']) || !wp_verify_nonce($_POST['acf_nonce'], 'input') ) return $post_id;
if(get_post_status( $post_id ) <> 'publish' ) return $post_id;
$location = (array) ( maybe_unserialize(get_post_meta($post_id, 'location', true)) ); //change location as your acf field name
if( count($location) >= 3 ) {
$geo_address = $location['address'];
$geo_latitude = $location['lat'];
$geo_longitude = $location['lng'];
$geo_location = ''.$geo_latitude.','.$geo_longitude.'';
update_post_meta( $post_id, 'geo_address', $geo_address );
update_post_meta( $post_id, 'geo_latitude', $geo_latitude );
update_post_meta( $post_id, 'geo_longitude', $geo_longitude );
update_post_meta( $post_id, 'geo_location', $geo_location );
}
}