By default, the search results are always ordered by distance, but this can be easily changed by using the wpsl_store_data filter.
The code example below shows how to sort the results alphabetically by store name:
Place the above code in the functions.php inside your active the folder, and make sure to flush the WPSL transient cache on the settings page before reloading the store locator. Once you have done that the search results should be ordered by store name instead of distance.
SORT_ASC
to SORT_DESC
on line 11.If you want to sort the search results by another field, you have to change the key that’s used in the $row
var on line 8, and set it to the name of the location data you want to base the sorting on.
The code example below sorts the search results by city:
You can use any data field to sort the search results. So sorting the search results on, for example, the id, address, city, zip, or a custom field is also possible.