Google Map field
Purpose
A place (an office, a venue, a store) as address, latitude, longitude and zoom.
Field type name
google_map
Settings
| Setting | Description |
|---|---|
| Instructions | Shown to editors below the field label. |
| Map Center Latitude | Where the map picker starts when nothing is chosen (-90 to 90). |
| Map Center Longitude | Same, longitude (-180 to 180). |
| Zoom | Zoom level of the map picker (1 = world, 21 = building). |
| Map Height | Height of the map picker in pixels (200-800). |
| Translation | How the field behaves in other languages: translate, copy, copy_once or do_not_translate. See WPML. |
| Width | Width on edit screens: 100, 75, 66, 50, 33 or 25 (%). |
| Label per language | The label and instructions per language code while editing in that language. See WPML. |
PHP return value
['address' => 'Dam 1, Amsterdam', 'lat' => 52.3730273, 'lng' => 4.8924534, 'zoom' => 14],
or null.
Example
$office = cafe_get_field( 'office' );
if ( $office ) {
printf(
'<a href="%s">%s</a>',
esc_url( 'https://www.google.com/maps/search/?api=1&query=' . rawurlencode( $office['lat'] . ',' . $office['lng'] ) ),
esc_html( $office['address'] )
);
}
Editing
- Without an API key: editors type the address, latitude and longitude.
- With a key (CAFE → Settings → Integrations → Google Maps API key, or the
cafe_google_maps_api_keyfilter): a map picker appears; search an address (Places autocomplete), click the map or drag the marker; the inputs follow. Google Maps is loaded once, only on edit screens that show a map field. If Google cannot be reached, the inputs keep working.