WP Geo search

WP Geo search

Wordpress plugin

Install on Wordpress

App Details

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" ) )) $query = new WP_Query(array( "geo_query" => array( "latitude" => -52.005, "longitude" => 0.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.

$query = new WP_Query(array( "geo_query" => array( "latitude" => -52.005, "longitude" => 0.005, "radius" => 10 ) )) 

Or order by nearness:

$query = new WP_Query(array( "geo_query" => array( "latitude" => -52.005, "longitude" => 0.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.

You could also hook into the save_post action to populate meta whenever you create or change a post, by adding a snippet like this to your theme’s functions.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

If you have many posts that you need to add longitude and latitude meta to in bulk, you could add something like this to functions.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'); 

Pricing

Starting from $0 per month.

Check Out the Social Share Buttons Widget

By Common Ninja

Social Share ButtonsTry For Free!

App Info

Rating

Reviewers

2 reviews

Tags

distance
geo
location

Developed By

jhackett1

Quick & Easy

Find the Best Wordpress plugins for you

Common Ninja has a large selection of powerful Wordpress plugins that are easy to use, fully customizable, mobile-friendly and rich with features — so be sure to check them out!

Testimonial

Testimonial plugins for Wordpress

Contact Form

Contact Form plugins for Wordpress

Maps

Maps plugins for Wordpress

Translation

Translation plugins for Wordpress

Chat

Chat plugins for Wordpress

Slider

Slider plugins for Wordpress

Reviews

Reviews plugins for Wordpress

Contact

Contact plugins for Wordpress

Galleries

Galleries plugins for Wordpress

SEO

SEO plugins for Wordpress

Forms

Forms plugins for Wordpress

Comments

Comments plugins for Wordpress

Backup

Backup plugins for Wordpress

Privacy

Privacy plugins for Wordpress

Optimize

Optimize plugins for Wordpress

Tabs

Tabs plugins for Wordpress

Social Sharing

Social Sharing plugins for Wordpress

Events Calendar

Events Calendar plugins for Wordpress

Comments

Comments plugins for Wordpress

Social Feeds

Social Feeds plugins for Wordpress

Social Sharing

Social Sharing plugins for Wordpress

Portfolio

Portfolio plugins for Wordpress

Video Player

Video Player plugins for Wordpress

popup

popup plugins for Wordpress

SiteMap

SiteMap plugins for Wordpress

Payment

Payment plugins for Wordpress

Coming Soon

Coming Soon plugins for Wordpress

Inventory

Inventory plugins for Wordpress

Testimonials

Testimonials plugins for Wordpress

Portfolio

Portfolio plugins for Wordpress

Membership

Membership plugins for Wordpress

Forms

Forms plugins for Wordpress

Analytics

Analytics plugins for Wordpress

Events Calendar

Events Calendar plugins for Wordpress

Sliders

Sliders plugins for Wordpress

Analytics

Analytics plugins for Wordpress

Reviews

Reviews plugins for Wordpress

Security

Security plugins for Wordpress

Ads

Ads plugins for Wordpress

Music Player

Music Player plugins for Wordpress

Countdown

Countdown plugins for Wordpress

Email Marketing

Email Marketing plugins for Wordpress

Membership

Membership plugins for Wordpress

Ecommerce

Ecommerce plugins for Wordpress

Customer Support

Customer Support plugins for Wordpress

Video Player

Video Player plugins for Wordpress

Tabs

Tabs plugins for Wordpress

Social Feeds

Social Feeds plugins for Wordpress

Common Ninja Apps

Some of the best Common Ninja plugins for Wordpress

Browse our extensive collection of compatible plugins, and easily embed them on any website, blog, online store, e-commerce platform, or site builder.

Social Share Buttons for Wordpress logo

Social Share Buttons

Add social share buttons so visitors share content to major networks, boost engagement, and drive more referral traffic.

RSVP Form for Wordpress logo

RSVP Form

Collect event responses with an RSVP form that lets guests register easily, saves submissions, sends notifications, and helps you organize attendance efficiently.

WhatsApp Chat for Wordpress logo

WhatsApp Chat

Add WhatsApp Chat to your site to communicate with visitors, deliver instant support, and create a smoother, more trustworthy user experience.

Blogger Feed for Wordpress logo

Blogger Feed

Show Blogger posts automatically with a Blogger feed that keeps your content fresh, improves navigation, and helps visitors discover more of your work.

RSS Feed for Wordpress logo

RSS Feed

Show fresh content from any source with an RSS feed that keeps your site updated, improves navigation, and boosts user engagement.

Timeline for Wordpress logo

Timeline

Use a timeline widget to display events and milestones in chronological order with images and text so visitors understand your story clearly.

Image Carousel for Wordpress logo

Image Carousel

Showcase images with an image carousel that rotates or slides visuals, improves design, and draws attention to key content.

Comparison Tables for Wordpress logo

Comparison Tables

Add comparison tables to your site to help visitors evaluate features side by side, understand differences quickly, and choose the right option with confidence.

Team Members Blobs for Wordpress logo

Team Members Blobs

Use team members blobs to present your staff in a clear, creative format that builds trust, supports transparency, and strengthens brand credibility.

News Ticker for Wordpress logo

News Ticker

Use a news ticker to display headlines and updates that highlight key information and keep users informed in real time.

Payment Button for Wordpress logo

Payment Button

Use a payment button for secure PayPal or Stripe checkout to simplify online payments and help increase sales.

Facebook Feed for Wordpress logo

Facebook Feed

Show Facebook posts in a live Facebook feed that keeps content fresh, boosts social proof, and helps visitors engage more with your brand.

More plugins

plugins You Might Like

Discover Apps By Platform

Discover the best apps for your website

WordPress
Wix
Shopify
Weebly
Webflow
Joomla
PrestaShop
Shift4Shop
WebsiteX5
MODX
Opencart
NopCommerce

Common Ninja Search Engine

The Common Ninja Search Engine platform helps website builders find the best site widgets, apps, plugins, tools, add-ons, and extensions! Compatible with all major website building platforms - big or small - and updated regularly, our Search Engine tool provides you with the business tools your site needs!

Multiple platforms