Enter or search an address with an autocomplete feature, using the Google Places API. This field is similar to the ACF Google Map “Search” field, but with more customizable behavior.
Setting name | Description |
Placeholder | Appears within the input |
Allow Countries | Limit the search to specific countries |
Search Type | Choose the allowed search type: None, Geocode (non-business), Address, Regions, Cities or Business |
Allow Geolocation | Allow the user to find their current location |
Allow Custom Address | Allow the user to enter an address not found in the Google Places API |
Prepend | Appears before the input |
Append | Appears after the input |
API Key | The Google API Key |
Individual Sub Fields | Choose which address component should be also saved as an individual sub field. For example: {my_field}_street_name |
$address = get_field('address');
/**
* array(
* 'address' => 'East Houston St/2 Ave, New York, NY, USA',
* 'lat' => 40.72397329999999,
* 'lng' => -73.99146499999999,
* 'place_id' => 'ChIJ5dnaVoRZwokRy1Cp3xQfuN0',
* 'name' => 'East Houston Street & 2 Avenue',
* 'city' => 'New York',
* 'state' => 'New York',
* 'state_short' => 'NY',
* 'post_code' => '10003',
* 'country' => 'United States',
* 'country_short' => 'US',
* )
*/
List of arguments passed to the Autocomplete library. See Google Places Autocomplete documentation.
/**
* acfe/fields/address/args
*
* @object args The autocomplete args
* @object field ACF Field instance
*/
filter('acfe/fields/address/args', args, field);
filter('acfe/fields/address/args/name=my_address', args, field);
filter('acfe/fields/address/args/key=field_608abfa17fa7f', args, field);
acf.addFilter('acfe/fields/address/args/name=my_address', function(args, field){
args.types = ['hospital', 'pharmacy', 'bakery', 'country'];
return args;
});
Triggered when the Google Places Autocomplete is initialized.
/**
* acfe/fields/address/init
*
* @object args The autocomplete instance
* @object field ACF Field instance
*/
action('acfe/fields/address/init', autocomplete, field);
action('acfe/fields/address/init/name=my_address', autocomplete, field);
action('acfe/fields/address/init/key=field_608abfa17fa7f', autocomplete, field);
acf.addAction('acfe/fields/address/init/name=my_address', function(autocomplete, field){
autocomplete.setComponentRestrictions({
country: ["us", "pr", "vi", "gu", "mp"],
});
});