I’m working on a website which was originally created by another developer. A while ago, I was tasked with updating all plugins on the site and upgrading WordPress to 3.8. This all went fine and everything still functioned properly after the updates (after a few tweaks). However, I have just noticed that a custom field called network_location can no longer be updated from the backend. I presume this is because the previous developer used a plugin called Advanced Custom Fields Location addon, which if I understand correctly has now been replaced with the Google Maps field in the core of ACF.
I have searched around but I couldn’t find a guide or advice on how to convert from a location field to a Google Maps field. I tried changing the field type in Custom Fields (at the moment it says “Error Field type does not exist”) to Google Maps, but then when I edit a post using the network_location field, none of the old data is shown and the map just shows the default Melbourne area.
So My question is, how can I import the previously entered latitude and longitude values provided with the Advanced Custom Fields Location plugin into the new Google Maps field?
When I look at the code on the front end for displaying the lat/long, it reads like this:
$longlat = get_post_meta($network->ID, 'network_location', true); // for some reason acf shorthand fails $ll = explode(";", $longlat); $return_points['markers'] = array('id' => $network->ID, 'latitude' => $ll, 'longitude' => $ll, 'title' => $network->post_title, 'content' => $content);
So that looks like latitude and longitude are stored side by side, separated by a ; .
Surely I can’t be the only user this has happened to, what are my options?
So I have done some checking and when I convert the field to a text field, the values are shown like this:
so the format is Latitude;Longitude.
I checked and with the Google Maps field option, the data is stored like this:
I have post codes for all of the locations, so is there a way of running a converter like script that will format the lat;long values in a way that makes them readable by the new Google Maps field?
I closely read the update_field() documentation and built a template that pulls the old content into the new fields.
Looked something like this, this is inside the loop:
// switch on "show field keys", see http://www.advancedcustomfields.com/resources/update_field/ $field_key = "field_somethingrandom"; //this is the new field $post_id = get_the_ID(); // the $address, $latitude, $longitude values come from the old fields $value = array( "address" => $address, "lat" => $latitude, "lng" => $longitude ); update_field( $field_key, $value, $post_id );
Be sure to back up your database, this can mess up your data.
You must be logged in to reply to this topic.
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!
© 2022 Advanced Custom Fields.