WordPress plugin intelligence profile

WP Geo search

Add location-aware geographical search to WP_Query. You can use it to power location-aware apps, such as showing a user results near them.

WP PlugIndex snapshot

Current directory snapshot

Tested up to WordPress 5.8
Current version0.1
WordPress coverageTested up to WordPress 5.8
Minimum stackWP 4.0 · PHP 7.0
Directory statusactive
Last directory update6 Sept 20215y ago
Active installations60Adoption metric — not a quality score
WordPress.org rating5.0 / 5 from 2 ratings
Official packageDirect from WordPress.org

Repository metrics are context, not quality scores. Active installations measure adoption and can strongly reflect a plugin’s age and historical popularity. Ratings, recent updates and “Tested up to” metadata also do not guarantee modern code, error-free operation, security, feature completeness or suitability for a particular site. Why active installs don’t tell the whole story →

WP PlugIndex currently records WP Geo search version 0.1 as active, updated 5y ago and tested up to WordPress 5.8.

Overview

About this plugin

A plugin to add location-aware geographical search to WP_Query.

You can use it to power location-aware apps, such as showing a user results near them.

🔎 Using it in a query

Adding a geo_query parameter to WP_Query will add a “distance” column to the returned results, provided they have the right metadata.

You can then display this in your templates.

You can use a location search parameter, which will be geocoded or directly provide latitude and longitude values:

$query = new WP_Query(array( "geo_query" => array( "location" => "London" ) ))

005, ) ))

Optionally, you can then filter by search radius.

By default, distances are given in miles. You can provide "units" => "km" if you need kilometres.

005, "radius" => 10 ) ))

Or order by nearness:

005 ), "orderby" => "geo" ))

Displaying distance in templates

In a WP_Query loop that includes a geo_query, you can use two extra functions to show distance away:

  • jhgs_get_the_distance(object $post) – which returns a rounded integer for the distance away, similar to get_the_title()

-

jhgs_the_distance(string $less_than_one, string $one, string $more_than_one) – which displays an approximate human-readable string, similar to the_title()

jhgs_the_distance will show one of three messages depending on whether the rounded distance is less than one, one, or greater than one. By default these are:

-

“Less than a mile away”

  • “About a mile away”
  • “About %s miles away”

If you need to use different units or translations, can pass three printf-formatted strings to jhgs_the_distance() to override these messages. Put %s where you want the value.

If you need the exact, unrounded value, you can use $post->distance.

Geocoding

Nominatim ‘s service is used for geocoding location searches.

Using it is subject to an acceptable use policy – if you use case will involve lots of API calls, you should replace it with a paid alternative, like Google ‘s.

📍 Populating latitude and longitude data

It looks for two custom field values with the keys latitude and longitude on your posts.

It’s agnostic about how you supply this data. The simplest thing to do is type it in using WordPress’s built-in custom field editor.

php:

function example_update_latlngs($post){ $location = get_field("location", $post); if(isset($location)){ update_post_meta($post, "longitude", $location["lng"]); update_post_meta($post, "latitude", $location["lat"]); } }

add_action("save_post", "example_update_latlngs", 10, 3);

This example assumes you are using an ACF Google Map field called “location”, but the data could come from anywhere, including a custom meta box you code yourself, so long as the post meta keys are right.

Bulk-updating existing posts

php, which will run on theme activation:

function example_update_all_latlngs(){ $query = new WP_Query(array( "posts_per_page" => -1 )); foreach($query->get_posts() as $post){ // Function from above example_update_latlngs($post); } }

add_action('after_switch_theme', 'example_update_all_latlngs');

WordPress.org metadata

Plugin tags

Topics listed for this plugin in the WordPress.org directory.

  • distance
  • geo
  • haversine
  • location
  • nominatim
Compatibility & maintenance

Compatibility & maintenance

Tested up to WordPress 5.8

Not yet marked as tested with WordPress 7.1. WordPress.org currently lists Tested up to 5.8.

Current WordPress releaseWordPress 7.1
WordPress.org Tested up to5.8
Minimum requirementsWordPress 4.0 · PHP 7.0
Update activity6 Sept 20215y ago

“Tested up to” is directory metadata supplied by the plugin author. WP PlugIndex does not turn an older declaration into a claim that the plugin is incompatible.

Changes recorded by WP PlugIndex

Recent tracked changes

No tracked version or compatibility changes have been recorded by WP PlugIndex yet.

Tracking & source

WP PlugIndex tracks public WordPress.org directory metadata and records selected version, compatibility and availability changes as they are detected.

Plugin watchlist

Watch this plugin

Sign in to your WP PlugIndex account or create a free account. Free accounts can watch up to 5 plugins and see what changed.

Watch limit

Watchlist limit reached

You have reached your current active watch limit.