Home › Forums › ACF PRO › Google Maps crashing when no location data passed › Reply To: Google Maps crashing when no location data passed
You need to check to see if the lat
and lng
indexes are set on the field array. You do this using the isset()
PHP method. If they aren’t shown you can display an error (or nothing) and if they are then proceed with the rest of your code.
$location = get_field('map');
if ( isset( $location['lat'] ) && isset( $location['lng'] ) ){
$lat = $location['lat'];
$lng = $location['lng'];
$coords = $lat.".".$lng;
// ... the rest of your code
} else {
// ... the lat/lng location is not set
}
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.