1. Home
  2. Docs
  3. Add-Ons
  4. Radial Search

Radial Search

How Radial Searches Work

When a search is performed by a user and a radius is specified, we take the address entered and use the Googles Geocoding service to convert this address into a latitude and longitude. We then query and return all properties that are within X miles of this lat/lng, using the co-ordinates entered onto the individual property records.

The Geocoding requests performed are cached thus ensuring only one lookup is performed per location searched.

As we use the Google Geocoding service you'll need to ensure the API key you have entered under 'Property Hive > Settings > General > Map' has access to the Geocoding Service. More about this can be found here.

 

Settings

The settings tab can be access under 'Property Hive > Settings > Radial Search':

From within the settings area there are a number of subsections:

Cache

As mentioned above all Geocoding requests are cached. Here you can view this cache as well as delete it

Search Forms

Contains information on how to add the Radius dropdown to your search forms, as well as the ability to enable the 'Use Current Location' functionality whereby the search will be based around a users current position.

Troubleshooting

The first place to head if the radius search isn't working as expected. Here you'll find information about the requirements surrounding the Google Maps API key, as well as a list of properties with no co-ordinates entered.

 

Adding A Radius Dropdown To Your Search Form

The Radial Search add on does not add the radius dropdown to search forms automatically. As a result, you can add it in one of two ways:

Option 1: Use Our Template Assistant Add On
Our Template Assistant add on is free and gives you the ability to control the fields shown in search forms through the WordPress interface using a drag-and-drop form builder.

Once activated navigate to 'Property Hive > Settings > Template Assistant > Search Forms' and edit the search form in question. You will notice that there is a 'Radius' option in the list of 'Inactive Fields' which you can then drag into the 'Active Fields' list.

Option 2: Adding It Manually Via Code
It can also be added without any additional plugins by inserting a short snippet of code to your theme's functions.php file.

NOTE: If you haven't read ourĀ 'Editing TheĀ Search Form' documentation yet, we recommend you have a read of that first before continuing.

// Note we're using 'default' as the identifier. Update this accordingly
add_filter( 'propertyhive_search_form_fields_default', 'edit_default_property_search_form_fields' );
 
function edit_default_property_search_form_fields($fields)
{
    // Add a location search field
    $fields['address_keyword'] = array(
        'type' => 'text',
        'label' => 'Location'
    );

    // Add a radius dropdown field
    $fields['radius'] = array(
        'type' => 'select',
        'label' => 'Radius',
        'options' => array(
          '0' => 'This Area Only',
          '1' => 'Within 1 Mile',
          '2' => 'Within 2 Miles',
          '3' => 'Within 3 Miles',
          '5' => 'Within 5 Miles',
          '10' => 'Within 10 Miles'
        )
    );
 
    return $fields; // return the fields
}

In the above code we're adding a 'Location' search box (allowing people to enter a town, city or postcode), as well as a radius dropdown with values ranging from 1-10 miles.

 

Accessing the Settings Area

Under 'Property Hive > Settings > Radial Search' you'll see a wide array of information including debugging information. If your radius search isn't working as expected, this is the first place to check.

 

Adding Bias

Sometimes a town/area name might exist in multiple places across the UK, for example 'Edmonton' or 'St Ives'. To get around this you can use a filter to append the location with the county or larger area to restrict results. An example of this can be found here:

https://gist.github.com/propertyhive/766be02f756b3100810b1cc433f9046a

Was this article helpful to you? No 1 Yes

How can we help?