Skip to content

Instantly share code, notes, and snippets.

@kevinwhoffman
Created January 22, 2016 01:21
Show Gist options
  • Save kevinwhoffman/be490f77ce0f47804f14 to your computer and use it in GitHub Desktop.
Save kevinwhoffman/be490f77ce0f47804f14 to your computer and use it in GitHub Desktop.
Split ACF Google Map Field Data Into Separate Custom Fields
<?php
/**
* In order for Google Maps Builder Pro to work with ACF map fields,
* lat and lng are saved as separate fields in the function below.
*/
function acf_save_lat_lng( $post_id ) {
// get value of ACF map field
$value = get_field( 'cel_map' );
// update lat and lng as separate custom fields
update_post_meta( $post_id, 'cel_lat', $value['lat'] );
update_post_meta( $post_id, 'cel_lng', $value['lng'] );
}
// run after ACF saves the $_POST['acf'] data
add_action('acf/save_post', 'acf_save_lat_lng', 20);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment