X Features Cars Demo Power Plants Demo State Parks Demo Site Showcase Docs Tutorials Add-ons Buy

Proximity

Overview

The proximity facet lets you find results near a specified location.

facet-proximity

IMPORTANT: For “locate me” to work, your site needs to be HTTPS-enabled. Learn more »

How it Works

After entering a location, FacetWP uses Google to grab the latitude, longitude of that location’s central point. Results within a user-defined radius of that point are displayed.

It does not understand geographic / political boundaries. If you search for a country (e.g. Italy), the facet will return results extending from that country’s center, which may include results from other countries.

Usage

The Data Source should be a custom field containing a comma-separated latitude, longitude.

Listify / Listable users: set the facet’s Data Source to geolocation_lat.

If your posts are not geocoded, try the Advanced Custom Fields plugin. Add a Google Map field to attach a location to your posts. To support multiple locations per post, wrap your Google Map field within a Repeater.

Alternatively, you could use the Address Geocoder plugin. If you go this route, then choose martygeocoderlatlng for the data source.

Available Options

Name Description
Other data source Choose a longitude field if stored separately from the latitude
Unit of measurement Miles or kilometers
Radius UI The UI for the radius selector (dropdown, slider, none)

Using a Google Maps API Key

The proximity facet requires a valid Google Maps API key. After generating an API key, add it to Settings > FacetWP > Settings.

Customize the Radius Options

The first array element is the default radius (feel free to change).

add_filter( 'facetwp_proximity_radius_options', function( $options ) {
    return array( 10, 25, 50, 100, 250 );
});

Limit Autocomplete to a Specific Country

Force the autocomplete to show only choices in Germany (country code = “de”).

add_filter( 'facetwp_proximity_autocomplete_options', function( $options ) {
    $options['componentRestrictions'] = array(
        'country' => 'de',
    );
    return $options;
});

Limit Autocomplete to Showing Cities

add_filter( 'facetwp_proximity_autocomplete_options', function( $options ) {
    $options['types'] = ['(cities)'];
    return $options;
});