Horje
Copy and modify the ACF google map co-ordinates to custom fields - Wordpress Solution
2 parts to this...
Part 1.
[[LINK href="http://wpquestions.com/question/showChronoLoggedIn/id/10746"]]Similar to this question[[/LINK]], but with ACF instead. I want to use the [[LINK href="https://wordpress.org/plugins/advanced-custom-fields/"]]ACF[[/LINK]] google map field with [[LINK href="https://wordpress.org/plugins/geo-mashup/"]]Geo Mashups[[/LINK]]. I don't want to use the Geo Mashup backend map, I want to use the ACF google map backend interface instead, but I need to be able to extract the latitude and longitude co-ordinates from the ACF data [[LINK href="http://support.advancedcustomfields.com/forums/topic/google-maps-field-normalization/"]]This may help to start the ball rolling[[/LINK]]. I want this ACF google map data to be COPIED and then SPLIT UP into 4 different custom fields ('geo_address', 'geo_location', 'geo_latitude' and 'geo_longitude'). So essentially each post will have 4 new custom fields created OR updated: geo_location = -32.069574412203,115.90815624919128 geo_address = 29 Smith Street Smithvile, Western Australia 6012 Australia geo_latitude = -32.069574412203 geo_longtitude = 115.90815624919128 I want a function for my functions.php file that will check ONLY those posts that are published and/or updated.
Part 2.
But that's not all... the ACF google map in the post edit won't show up the actual map as it conflicts with the Geo Mashup google map. Therefore I'd like the Geo Mashup map on the post edit page to go away, or in the very least not conflict with the ACF google map. I'm only using the Geo Mashup plugin for it's mashup capability so please keep that intact. Hi Sir, Part 1 put following code into theme's functions.php those custom fields will not be created if the post status is not "publish" or update after published change location as your acf field name.

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 );

   }

}
Part 2 Go to Geo Mashup Options Select OpenLayers as Map Provider Thanks i'll test it now OK, Part one seems to work but part 2 isn't what i'm looking for. I still want the google map interface to show on the mashup page... by ticking the OpenLayers it doesn't show the Google Map. it works on my envirnment, both on backend (separately) and frontend.

Solution - 1

Hi Sir, Part 1 put following code into theme's functions.php those custom fields will not be created if the post status is not "publish" or update after published change location as your acf field name.


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 );

   }

}
Part 2 Go to Geo Mashup Options Select OpenLayers as Map Provider





Wordpress

Related
Need help about this plugin - Wordpress Solution Need help about this plugin - Wordpress Solution
How to allow users to manage only own terms in custom taxonomy - Wordpress Solution How to allow users to manage only own terms in custom taxonomy - Wordpress Solution
Display taxonomy terms, child terms and posts in a template - Wordpress Solution Display taxonomy terms, child terms and posts in a template - Wordpress Solution
Gravity Form + Custom Field dropdown interaction - Wordpress Solution Gravity Form + Custom Field dropdown interaction - Wordpress Solution
Post per page dropdown and pagination fix - Wordpress Solution Post per page dropdown and pagination fix - Wordpress Solution

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
10