google-maps-builder icon indicating copy to clipboard operation
google-maps-builder copied to clipboard

Add support for ACF maps field

Open mathetos opened this issue 8 years ago • 2 comments

@mathetos commented on Thu Apr 28 2016

Many users leverage ACF to add map data into their custom post types. It stores the long/lat as an array, but the Maps Builder looks for each in their own fields. If we could translate their array into our lat/long automatically it would be much easier for our users.

Kevin Hoffman contributed this code for his own solution:

add_action( 'acf/save_post',  'my_acf_save_post',  20 );
function my_acf_save_post(  $post_id  ) {
  $map = get_field(  'cel_map'  ); // ACF map field containing array of map data
  if (  $map  ) {
    update_post_meta(  $post_id,  'cel_lat',  $map['lat']  ); // Used in Maps Builder mashup
    update_post_meta(  $post_id,  'cel_lng',  $map['lng']  ); // Used in Maps Builder mashup
  }
}

mathetos avatar Jul 07 '16 23:07 mathetos