BP Profile Search › Location Search
-
AuthorPost
-
Michael Spencer
GuestAndrea,
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 Michaelandrea
Plugin AuthorHi 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.
Michael Spencer
GuestAndrea, 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
Michaelandrea
Plugin AuthorHi 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.
Michael Spencer
GuestAndrea, 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, UKWhereas 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, UKThe 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
Michaelandrea
Plugin AuthorHi 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!
-
AuthorPost