
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.
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" ))
In a WP_Query loop that includes a geo_query, you can use two extra functions to show distance away:
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”
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.
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.
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.
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'); Starting from $0 per month.
Rating
Reviewers
2 reviews
Tags
Developed By
jhackett1
Quick & Easy
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 plugins for Wordpress
Galleries plugins for Wordpress
SEO plugins for Wordpress
Contact Form plugins for Wordpress
Forms plugins for Wordpress
Social Feeds plugins for Wordpress
Social Sharing plugins for Wordpress
Events Calendar plugins for Wordpress
Sliders plugins for Wordpress
Analytics plugins for Wordpress
Reviews plugins for Wordpress
Comments plugins for Wordpress
Portfolio plugins for Wordpress
Maps plugins for Wordpress
Security plugins for Wordpress
Translation plugins for Wordpress
Ads plugins for Wordpress
Video Player plugins for Wordpress
Music Player plugins for Wordpress
Backup plugins for Wordpress
Privacy plugins for Wordpress
Optimize plugins for Wordpress
Chat plugins for Wordpress
Countdown plugins for Wordpress
Email Marketing plugins for Wordpress
Tabs plugins for Wordpress
Membership plugins for Wordpress
popup plugins for Wordpress
SiteMap plugins for Wordpress
Payment plugins for Wordpress
Coming Soon plugins for Wordpress
Ecommerce plugins for Wordpress
Customer Support plugins for Wordpress
Inventory plugins for Wordpress
Video Player plugins for Wordpress
Testimonials plugins for Wordpress
Tabs plugins for Wordpress
Social Sharing plugins for Wordpress
Social Feeds plugins for Wordpress
Slider plugins for Wordpress
Reviews plugins for Wordpress
Portfolio plugins for Wordpress
Membership plugins for Wordpress
Forms plugins for Wordpress
Events Calendar plugins for Wordpress
Contact plugins for Wordpress
Comments plugins for Wordpress
Analytics plugins for Wordpress
Common Ninja Apps
Browse our extensive collection of compatible plugins, and easily embed them on any website, blog, online store, e-commerce platform, or site builder.
Use a pricing slider to show dynamic prices by quantity, help visitors compare options, and support confident purchases.
Create interactive polls with a poll widget that gathers real-time feedback, boosts engagement, and helps you understand visitor opinions quickly and clearly.
Display social proof avatars that show user activity and ratings, build trust instantly, and help visitors feel confident about your credibility.
Add animated headlines to draw attention to key messages and improve user engagement through visual emphasis.
Show progress with animated progress circles that visualize goals, display achievements, and keep visitors engaged.
Add an Instagram slider to your site to display social posts dynamically and keep your visual content engaging and current.
Use a coupon popup to highlight special offers, capture email leads, reduce cart abandonment, and turn more visitors into paying customers.
Create interactive infographics with a ratio widget that uses custom icons, dynamic tooltips, and clear visuals to help visitors understand data quickly.
Use a timeline widget to display events and milestones in chronological order with images and text so visitors understand your story clearly.
Add a PDF viewer to your site to display documents, share product information, and give visitors easy access to helpful content in one place.
Add social media and RSS feeds to your site to display fresh content, grow your online presence, and keep visitors engaged with real-time updates.

Show Tumblr posts with a Tumblr feed that keeps content fresh, improves navigation, and helps visitors discover more posts.
More plugins
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!
