How to remove latitude and longitude from Google Maps ACF field in WordPress?

In WordPress, there’s an Advanced Custom Fields Google Map option. I’m using that to refer to the address as text at one point. Code used:

<?php the_field('address');?>

Address is the custom variable for the Google Map.

Read More

This displays the street, city, state, zip code, country and latitude and longitude.

I don’t need the country, lat or long. I’ve been trying to find an array I can edit, but no luck so far.

Thanks!

Related posts

Leave a Reply

1 comment

  1. If you use get_field() instead of the_field() it will give you an array of 3 elements: address, lat and lng.

    Unfortunately address is a string with the full address, country name included.
    But if it’s always the last voice separated by a comma, you can retrieve just the address string until the last comma, something like this:

    $location = get_field('address');
    if(isset($location['address'])) {
        $address = substr($location['address'], 0, strrpos($location['address'], ','));
        echo $address;
    }