pjeaje

Google map using ACF and Geo Mashups

Sep 24th, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. // http://support.advancedcustomfields.com/forums/topic/acf-and-geo-mashup-integration/
  2. // http://wpquestions.com/question/showLoggedIn/id/10778
  3. // How to combine multiple locations onto one Google map using ACF and Geo Mashups
  4. //
  5. // This is how you integrate ACF’s Google Maps field with Geo Mashup.
  6.  
  7. add_action('save_post', 'wpq_acf_gmap');
  8.  
  9. function wpq_acf_gmap($post_id) {
  10.  
  11.    if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
  12.  
  13.    if( !isset($_POST['acf_nonce'], $_POST['fields']) || !wp_verify_nonce($_POST['acf_nonce'], 'input') ) return $post_id;
  14.  
  15.    
  16.  
  17.    if(get_post_status( $post_id ) <> 'publish' )  return $post_id;
  18.  
  19.      
  20.  
  21.    $location   = (array) ( maybe_unserialize(get_post_meta($post_id, 'location', true)) ); //change location as your acf field name
  22.  
  23.    if( count($location) >= 3 ) {
  24.  
  25.       $geo_address = $location['address'];
  26.  
  27.       $geo_latitude = $location['lat'];
  28.  
  29.       $geo_longitude = $location['lng'];
  30.  
  31.       $geo_location = ''.$geo_latitude.','.$geo_longitude.'';
  32.  
  33.       update_post_meta( $post_id, 'geo_address', $geo_address );
  34.  
  35.       update_post_meta( $post_id, 'geo_latitude', $geo_latitude );
  36.  
  37.       update_post_meta( $post_id, 'geo_longitude', $geo_longitude );
  38.  
  39.       update_post_meta( $post_id, 'geo_location', $geo_location );
  40.  
  41.    }
  42.  
  43. }
Add Comment
Please, Sign In to add comment