Since version 1.4.0, WP Ultimate Search Pro has been capable of searching location meta-data attached to a post, autocompleting addresses as a user types them in. You can see a demo of this in action here.

First, in order to make your posts searchable by location, they need to have location meta-data associated with them. We recommend using an Advanced Custom Fields Google Map Field for the best compatibility. Add a map field to your posts, and give addresses to some of your content. Then, go into the WP Ultimate Search settings and switch to the Post Meta tab. Find your map field, and choose Radius under the Type dropdown.

Next, you’ll want to create a custom WPUS results template. The results template has several variables available to it that allow you to access and manipulate the map data:

  • $location['address'] is the plain text address that was entered by the user.
  • $location['lat'] is the latitude of the address that was entered by the user.
  • $location['lng'] is the longitude of the address that was entered by the user.

Displaying results on a map

How you display the results on the map will largely depend on what mapping library you use. On the demo site, we’re using Leaflet.js. To use Leaflet, first create a page with a map, following the Quick Start Guide. Then initialize and configure the map instance: ='map').setView([35.6672, -105.9644], 12);
L.tileLayer('http://{s}{z}/{x}/{y}.png', {
    maxZoom: 18

Notice that we’re using so our map object is available to the WPUS results template.

Once your map has been initialized, you need to add a little bit of JavaScript to the results loop to grab the latitude and longitude from each result and add a pin to the map. For an example of how to do this, you can download a sample wpus-results-template.php file. This is the same results template file we’re using on the demo site.

If you encounter any problems, or have any questions, please start a thread in the support forum, and we’d be happy to help you out.