Location Search

Home Forums BP Profile Search Forum Location Search

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #10662 Reply
    Michael Spencer
    Guest

    Andrea,
    Is it possible to set a default distance in the distance field of the search form – I am thinking of 5 miles.
    Do the search results appear in distance order? If not can they be amended so they do.
    Also it would be good to show the distance in the search results – is this possible?
    Regards Michael

    #10663 Reply
    andrea
    Keymaster

    Hi Michael,

    Add this code to your bp-custom.php file:

    add_action ('bps_field_before_search_form', 'set_defaults');
    function set_defaults ($f)
    {
    	if ($f->code == 'field_82' && $f->display == 'distance')
    	{
    		$f->value['distance'] = 5;
    		$f->value['units'] = 'miles';
    	}
    }

    Replace 82 with the actual field ID of your location field.

    The distance is shown in the search results when you run a distance search (you need the latest version of BP Distance Search), but to sort the results by distance you have to manually select the relevant option from the Order By: drop-down.

    #10664 Reply
    Michael Spencer
    Guest

    Andrea, Thank you, helpful as always. I am not seeing the distance in the results although this is probably because I am using custom member loop files with a lot of the original code removed. Can you point me to the code I need to put back?

    Regards
    Michael

    #10665 Reply
    andrea
    Keymaster

    Hi Michael,

    Please make sure you have this line in your members loop:

    do_action( 'bp_directory_members_item' );

    The location and distance will appear in place of that line.

    #10666 Reply
    Michael Spencer
    Guest

    Andrea, Thank you again for your terrific support. Unfortunately this has thrown up a problem in my case as I am using 3 locations fields from other code you kindly provided. When I do a search – location 1 place and distance are reported back, rather than location 2 or 3 if it is one of them that is actually the nearest. So for example on a London based search within 5 miles I got back

    Distance: Hog Hill Road, Romford RM5 2DH, UK (distance 14 miles)
    Location(s):
    Hog Hill Road, Romford RM5 2DH, UK
    Cavendish Square, London W1G 0PH, UK
    Nuffield Hospital Littleover, Derby DE23 4SN, UK

    Whereas I need

    Distance: Cavendish Square, London W1G 0PH, UK (distance 3 miles)
    Location(s):
    Hog Hill Road, Romford RM5 2DH, UK
    Cavendish Square, London W1G 0PH, UK
    Nuffield Hospital Littleover, Derby DE23 4SN, UK

    The search code you provided was

    add_filter (‘bps_field_sql’, ‘change_query’, 10, 2);
    function change_query ($sql, $f)
    {
    if ($f->code == ‘field_139’ && $f->filter == ‘distance’)
    $sql[‘where’][1] = ‘field_id IN (139,140,141)’;
    return $sql;
    }

    Are you able to help yet again?

    Regards
    Michael

    #10668 Reply
    andrea
    Keymaster

    Hi Michael,

    Unfortunately, while the search can be “tricked” to search in more than one field, it’s not possible to have the plugin display “the closest result” and then sort the directory based on “the closest result”.

    Both the display of results and the sorting of directories work with a given specific field, and in your case it’s your first location field.

    So the first location field is displayed and, even if you remove the display, the directory is still sorted by the distance from the first location (when you select that ordering option).

    Sorry I’m unable to help this time!

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: Location Search
Your information: