Home › Forums › ACF PRO › Populate Google Map lng/lat › Reply To: Populate Google Map lng/lat
Hey Derk…
You’re pretty close here.. but the object you’ll use to prepopulate the ACF field is the value of the field (for each post), rather than the field itself..
Perhaps something like below:
function my_acf_import_address( $value, $post_id, $field )
{
// Only do this if there is not a google_map
// value already in this post's fields
if ( empty( $value ) )
{
// Here I'm assuming the old map function stored
// the address, lat & lng as post meta & not as custom fields
$address = get_post_meta( $post_id, '_job_location', true );
$lat = get_post_meta( $post_id, 'geolocation_lat', true );
$lng = get_post_meta( $post_id, 'geolocation_long', true );
// Now we assign the returned meta values to the
// value array to be returned
$value['address'] = $address;
$value['lat'] = $lat;
$value['lng'] = $lng;
}
return $value;
}
add_filter('acf/load_value/name=google_map', 'my_acf_import_address', 10, 3);
Hope this helps!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.