WPSolr logo
  • Brands & Agencies 💛
  • Products
    • Parsing & Chunking
    • Search
      • Algolia  Search
      • Apache Solr  Search
      • Elasticsearch  Search
      • Google AI Commerce  Search
      • OpenSearch  Search
      • OpenSolr  Search
    • AI Search
      • OpenSearch  AI Search
      • PostgreSQL  AI Search
      • Vespa  AI Search
      • Weaviate  AI Search
    • AI Recommendations
      • Amazon Personalize  AI Recommendations
      • Recombee  AI Recommendations
    • AI Personalized Search & Recommendations
      • Algolia  AI Personalized Search & Recommendations
      • Google AI Commerce  AI Personalized Search & Recommendations
  • Learn
    • Documentation & Guides – Everything to get started fast
    • Youtube – 100 practical videos from setup to live site demos
    • Forums – Direct support from our team
    • Blog
  • Pricing
  • My licenses
  • Meet
  • 📞  Call
    • 📞  US : (951) 612-8259
    • 📞  France : 01 62 04 55 85
  • Brands & Agencies 💛
  • Products
    • Parsing & Chunking
    • Search
      • Algolia  Search
      • Apache Solr  Search
      • Elasticsearch  Search
      • Google AI Commerce  Search
      • OpenSearch  Search
      • OpenSolr  Search
    • AI Search
      • OpenSearch  AI Search
      • PostgreSQL  AI Search
      • Vespa  AI Search
      • Weaviate  AI Search
    • AI Recommendations
      • Amazon Personalize  AI Recommendations
      • Recombee  AI Recommendations
    • AI Personalized Search & Recommendations
      • Algolia  AI Personalized Search & Recommendations
      • Google AI Commerce  AI Personalized Search & Recommendations
  • Learn
    • Documentation & Guides – Everything to get started fast
    • Youtube – 100 practical videos from setup to live site demos
    • Forums – Direct support from our team
    • Blog
  • Pricing
  • My licenses
  • Meet
  • 📞  Call
    • 📞  US : (951) 612-8259
    • 📞  France : 01 62 04 55 85
  • Brands & Agencies 💛
  • Products
    • Parsing & Chunking
    • Search
      • Algolia  Search
      • Apache Solr  Search
      • Elasticsearch  Search
      • Google AI Commerce  Search
      • OpenSearch  Search
      • OpenSolr  Search
    • AI Search
      • OpenSearch  AI Search
      • PostgreSQL  AI Search
      • Vespa  AI Search
      • Weaviate  AI Search
    • AI Recommendations
      • Amazon Personalize  AI Recommendations
      • Recombee  AI Recommendations
    • AI Personalized Search & Recommendations
      • Algolia  AI Personalized Search & Recommendations
      • Google AI Commerce  AI Personalized Search & Recommendations
  • Learn
    • Documentation & Guides – Everything to get started fast
    • Youtube – 100 practical videos from setup to live site demos
    • Forums – Direct support from our team
    • Blog
  • Pricing
  • My licenses
  • Meet
  • 📞  Call
    • 📞  US : (951) 612-8259
    • 📞  France : 01 62 04 55 85
Expand All Collapse All
  • What is WPSOLR ?
    • The standard WordPress SQL search
    • The WPSOLR search with Elasticsearch, Apache Solr, or Algolia
  • Your configuration journey, step by step
    • Install Apache Solr
    • Hosted Apache Solr and SolrCloud Services
    • Install Weaviate
    • Install Opensearch
    • Install Elasticsearch
    • Elasticsearch Hosting
    • Configure search
      • Getting started with search
      • Getting started with Ajax (live) search
      • Getting started with facets
      • 0. Connect your indexes
        • Create a Google Retail search index
        • Create an Elasticsearch index
          • Generate a test Elasticsearch index
          • Create an Elastic Elasticsearch index
          • Create an Elasticsearch index
          • Create a Qbox Elasticsearch index
          • Create an ElasticPress Elasticsearch index
          • Create an Aiven Elasticsearch or OpenSearch index
          • Create a Bonsai Elasticsearch index
          • Create an Amazon AWS Elasticsearch index
          • Create an ObjectRocket Elasticsearch index
          • Create a Cloudways Elasticsearch or Opensearch index
          • Create an Alibaba Cloud Elasticsearch index
          • Create a Compose Elasticsearch index
          • Connect to an Elasticsearch index
        • Create an Apache Solr index
          • Generate a test Apache Solr index
          • Create an Apache Solr index
          • Create a SearchStax SolrCloud index
          • Create an Opensolr Solr index
          • Connect to an Apache Solr index
        • Create an Opensearch index
          • Create a WPSOLR Hosting OpenSearch index
          • Create an Amazon AWS OpenSearch index
        • Create a Weaviate index
          • Weaviate with Google PaLM API
          • Weaviate with GPT4All
          • Weaviate with sentence transformers
          • Weaviate with CLIP text-to-image
          • Weaviate with HuggingFace Endpoints API
          • Weaviate with OpenAI GPT API
          • Weaviate with Cohere Multilingual API
          • Weaviate with Question Answering transformers
          • Weaviate with Hybrid search
          • Weaviate with Reranker - Cohere
          • Weaviate with Reranker - Transformers (cross-encoders)
        • Create an Algolia index
      • 1. Activate extensions (Add-ons)
        • bbPress add-on
        • YITH WooCommerce Ajax Search add-on
        • SEO add-ons
          • Yoast SEO add-on
          • All in One SEO add-on
        • Listable add-on
        • ACF add-on
        • Advanced Scoring add-on
        • Cron Scheduling add-on
        • Theme add-on
          • Filters layouts
            • Radiobox & Checkbox Layout
            • Numeric Range Layout
            • Colour Picker Layout
            • Date Picker (Flatpickr) Layout
            • Range Slider Layout
          • Add Ajax to the current Theme
          • Collapse taxonomy hierarchies
          • Custom Facets CSS
        • WPML add-on
        • Premium add-on
          • Manage more than one Elasticsearch or Solr index
        • PDF Embedder add-on
        • Geolocation add-on
        • AI Natural Language APIs add-on
          • Amazon Comprehend
          • Google Natural Language
          • Aylien Text Analysis
          • MeaningCloud
          • Qwam Text Analytics
        • Toolset Types add-on
        • AI Image and OCR APIs add-on
          • Google Vision
          • Amazon Rekognition
        • Embed Any Document add-on
        • MyListing add-on
        • Polylang add-on
        • WooCommerce add-on
        • Cross-domain federated search add-on
        • Directory+ add-on
        • Toolset Views add-on
        • Listify add-on
        • Jobify add-on
        • Query Monitor add-on
      • 2. Define your search
        • 2.3 Boosts
        • 2.3 Suggestions (Ajax search)
        • 2.1 Search
        • 2.2 Data
      • 3. Index your data
    • Configure recommendations
      • Algolia - Recommend and Personalized search
      • Recombee - Recommendations
      • Google Retail - AI Recommendations and Personalized search
      • Amazon Personalize
    • Configure WPSOLR Parsing and Chunking
    • Create your Custom Templates for Citations, Suggestions, Related Posts & Recommendations
  • Quick start

Geolocation add-on

1362 views 0 March 15, 2017 Updated on July 13, 2019

Geolocation extension: how does it work ?
Geolocation extension: how does it work ?

In wpsolr, Geolocation search, also named proximity search or search by distance, consists of using the location of a visitor to improve the search results.

What is it ?

Imagine you are writing reviews of restaurants in your region (you’re living in France). It would be nice to show the restaurants close to your visitors, no ?

Well, with wpsolr, you can.

Basically, you just need to create a custom field on your review post type, and fill it with the latitude and longitude of the restaurant.

Easily done with wikipedia informations.

Then, you activate the Geolocation features of wpsolr, and that’s it. Wpsolr can now use the location of your visitor, with his agreement, to sort results by the closest restaurant reviews.

 

Description for a visitor

  • (Optional) A visitor selects “search with distances” if it is configured (see wpsolr administrator setup below). If it is not configured, the next step applies directly.

    wpsolr geolocation search box with location checkbox
    wpsolr geolocation search box with location checkbox
  • The visitor submits his search
  • The visitor agrees, for once or for longer, to let the website know his location (this is asked by the browser, not by wpsolr). If the visitor does not agree, the search is performed without Geolocation, as usual.

    The browser asks geolocation location authorizaton
    The browser asks geolocation location authorization
  • The visitor location, latitude and longitude, is added to the search parameters, and the search is started
  • Wpsolr uses the location to perform a geolocation search, sorted and filtered by distance.

    wpsolr geolocation search results with distance
    wpsolr geolocation search results with distance

 

Activate the Geolocation Extension

This is your mandatory first step if you want to complete your geolocation setup.

 

Configure your Geolocation custom fields

Your location coordinates are probably contained in a custom field with a ‘lat,long’ format. If not, use our actions/filters to convert your coordinates format, or contact us to see what we can do for you.

To be treated as Geolocation fields, your custom field must be indexed, and searched, with a specific format in Apache Solr or Elasticsearch. For that, select a field type “LatLong”  as shown below (before indexing your data):

Select a 'Geolocation' type for your custom fields containing 'lat,long' data
Select a ‘Geolocation’ type for your custom fields containing ‘lat,long’ data. Then (re)index.

If your custom field is an ACF Google Map field type, you can use it too as shown below (you must activate and configure the ACF extension options first):

Select a type "Geolocation" for your ACF Google Map field. Then (re)index.
Select a type “Geolocation” for your ACF Google Map field. Then (re)index.

 

Use your Geolocation custom fields as a distance sort

Geolocation custom fields are sortable by default. The distance from each search result to the visitor (or any coordinates in the search url parameters) can be used to sort results.

You just have to add your Geolocation custom field to the sort fields. There is no difference with other ‘ordinary’ custom fields:

Use a geolocation custom field as sort by distance
Use a geolocation custom field as sort by distance

 

Select a default sort

You can select which sort to apply by default on geolocated searches, when none is selected by the user.

Select a default sort when the search is geolocalized
Select a default sort when the search is geolocalized

You can:
– Use the default sort used by all searches
– Override the default sort with another custom field (distance or not) when the search is localized

 

Create the text showing the distance in each search result

This is valid only for the Ajax template delivered with the plugin. To add the distance to your own theme’s search page template, follow the questions/answers at the end of this documentation.

You can decide how to show, or not to show at all, the distance to the visitor (or any other coordinates passed as url parameters) for every result.

Define your text pattern to show distances on each result
Define your text pattern to show distances on each result

Leave the field empty if you do not wish to show distance.

%1$s is replaced by the field label. %2$s is replaced by the distance. Use your theme/plugin .mo files or WPML string module to localize it.

 

Attach the Geolocation javascript to your own search form(s)

This option is for your theme’s search boxe(s). The Ajax default theme is already configured.

Attach the geolocation javascript to your theme's search boxe(s) with a jQuery selector
Attach the geolocation javascript to your theme’s search boxe(s) with a jQuery selector

Enter a jQuery selector for your search box(es). The javascript will collect the visitor localization precisely when the search is submitted from the search box(es). Also, the submitted form is added the css class “wpsolr_geo_loading” while the browser is retrieving the visitor location. You can use this class to show some loading icon for instance.

 

Add a user agreement checkbox on your search form(s)

Configure the user agreement to get his coordinates captured
Configure the user agreement to get his coordinates captured
  1. If you select this option, a checkbox will be added to the search form(s), wpsolr Ajax and your search form(s) defined above, asking the user to confirm his agreement to use his geolocation. If you do not select this option, the geolocation will be used without consent. (but the browser will ask anyway in both cases).
  2. The user agreement checkbox is preselected, or not.
  3. Text of the checkbox. Will be shown on the front-end (and translated in WPML/POLYLANG string modules if not empty. Else will show the localization translation).

 

Filter out results with no coordinates

Filter results without coordinates
Filter results without coordinates

If some of your post types does not contain geolocation coordinates, this option will filter them out from the results. It prevents showing messy wrong distances of 1000s of kilometers.

 

The browser does not ask visitors for their location ?

The browser asks geolocation location authorizaton

You should first check your browser javascript console logs, there are probably detailed explanations (unfortunately, the error is silent). But most recent browsers require websites to be protected by HTTPS to prompt visitors for their coordinates agreement.

 

How to add distance to your theme search results ?

WPSOLR adds a field ‘wpsolr_distance’ to the posts returned by the search. The field contains an array of distances, one by geolocalized custom field (you can have one, or more).

In your main loop, add code similar too:

<?php 
if ( ! empty( $post->wpsolr_distance ) ) {
foreach ( $post->wpsolr_distance as $field ) {
   echo sprintf( '%s km', $field->distance );
  } // foreach
} // if
?>

Was this helpful?

Yes  1 No
Related Articles
  • Configure WPSOLR Parsing and Chunking
  • Create a WPSOLR Hosting OpenSearch index
  • Create your Custom Templates for Citations, Suggestions, Related Posts & Recommendations
  • Getting started with facets
  • Getting started with Ajax (live) search
  • Getting started with search

Didn't find your answer? Contact Us

Previously
PDF Embedder add-on
Up Next
AI Natural Language APIs add-on

Built for brands and agencies worldwide

Adobe
Software Development
10K+ employees
Harvard University
Higher Education
798K alumni
University of Essex
Higher Education
101K alumni
Tally
Software development
501-1K employees
WebFX
Advertising Services
501-1K employees
DEFINITION 6
Advertising Services
1K-5K employees
Proto Thema
Newspaper Publishing
51-200 employees
The Fold London
Retail Apparel and Fashion
11-50 employees
Georgia-Pacific LLC
Paper and Forest Product Manufacturing
10K+ employees
Agencies, Software, Universities, Media, Newspapers, Publishers, Retails, Manufacturing, E-Commerce. And many more »

Recommended content

Powered by WPSOLR Enterprise with Recombee

Understand Where Your Store Is Losing Sales
Join our Affiliate Program!
Features
Search Hosting for WordPress
File Parsing and Chunking
Integration Hub
Search
Facets (Filters)
Search Add-ons
Recommendations
Keyword search engines
Comparison grid
Apache Solr & Solr Cloud
Elasticsearch
OpenSearch
Algolia
AI search engines
Comparison grid
PostgreSQL pgvector
Weaviate
Google Retail
Vespa.ai
OpenSearch vector
AI recommendation engines
Comparison grid
Recombee
Amazon Personalize
AI personalization engines
Comparison grid
Google Retail
Algolia
Buy and Learn
Pricing
Privacy policy
Terms and Conditions
© 2026 Eostis SARL. All Rights Reserved.
More
My licenses
Support
Documentation
Blog
Recommendations powered for you by WPSolr
Manage Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
View preferences
  • {title}
  • {title}
  • {title}