Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Copy and modify the ACF google map co-ordinates to custom fields WordPress

  • SOLVED

2 parts to this...

<blockquote>Part 1.</blockquote>
[[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:

<strong>geo_location</strong> = -32.069574412203,115.90815624919128
<strong>geo_address</strong> = 29 Smith Street Smithvile, Western Australia 6012 Australia
<strong>geo_latitude</strong> = -32.069574412203
<strong>geo_longtitude</strong> = 115.90815624919128

I want a function for my functions.php file that will check ONLY those posts that are published and/or updated.

<blockquote>Part 2.</blockquote>
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.

Answers (1)

2015-04-16

timDesain Nanang answers:

Hi Sir,
<strong>Part 1</strong>
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 <strong>location</strong> 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 );

}

}


<strong>Part 2</strong>
Go to Geo Mashup Options
Select <strong>OpenLayers </strong> as Map Provider


pjeaje comments:

Thanks i'll test it now


pjeaje comments:

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.


timDesain Nanang comments:

it works on my envirnment, both on backend (separately) and frontend.