1. Docs
  2. Add Ons
  3. Radial Search

Radial Search

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? Yes No