Hello,
we are creating a listing directory with toolset (hidden link) we will be glad to share it in your showcase.
We are now in trouble because we need to offer a filter and offer the user the possibility to list all custom posts in order by distance from the selected location:
we need google maps to convert the selected location to coordinates, and list all the posts by distance from those coordinates.
I have included a photo to help this to be understood.
Thanks for your great and detailed support,
Mario
Hi, you can add a Distance filter to any custom search View. Your site visitors can enter any location in the filter, choose a radius, and set other custom search filters. Then Views will show results within that radius. We have a map search available in our Real Estate reference site, which you can play with at discover-wp.com. We also have documentation available here:
https://toolset.com/documentation/user-guides/display-on-google-maps/
https://toolset.com/documentation/user-guides/display-on-google-maps/filtering-and-ordering-map-markers-by-distance/
Thank you Christian,
that's a good starting point, but our real need is to list all the custom posts in order of distance to the location set in the filter. Currently what is proposed is to show only the posts that fit the radius set in the filter, but we would need to show ALL posts, in order from more close to more distant to the location in the filter,
We think that is a very intuitive search that any one would like to have available in a directory. To list all the posts by distance from the location you set.
How can we apply this order from a filter?
thank you very much for all your support,
Mario
I see, I misunderstood. In the current system, you have a couple of different options.
1. Add a distance filter, and let the User set the location using the autosuggest field. This guarantees their location will be precise for calculations. Set the radius to a high number like 20000km to ensure all results are found. Unfortunately there's not an easy way to customize the text, radius and unit input fields on the front-end.
2. Add a postmeta control for the custom address field, but do not add a corresponding Query Filter. Use the URL parameter of the postmeta control to set the Ordering criteria (see attachment):
[wpv-control-postmeta field="wpcf-book-location" url_param="toolset_maps_distance_center"]
This option gives you the ability to hide all the unnecessary inputs and text, but it isn't guaranteed the User will enter a precise location because it doesn't utilize the autosuggest field. The calculations may be inaccurate.
Thank you Christian!
That sounds really good!
I would like to implement the second option. I would like to understand with detail the correct way to apply it, and what advantage will offer.
It has not been easy for me to understand this field: wpcf-book-location too,
Thank you in advance for your patience, its greatly appreciated,
Mario
I would like to implement the second option. I would like to understand with detail the correct way to apply it, and what advantage will offer.
- Edit the View. Scroll to the top right corner and click "Screen Options". Make sure the "Search and Pagination" section is active.
- In the Search and Pagination section, click "Add Filter" and choose the custom address field. My example field is called "book-location" but yours will be something else. In the filter options popup, choose "Text input" as the type of control, and in the URL parameter field enter "toolset_maps_distance_center". See popup.png.
- Scroll up to the Query Filter section. If you cannot see the Query Filter section, click "Screen Options" again to activate it. Then delete the address custom field filter from the Query Filter panel.
- In the Ordering section, choose your address custom field and "Ascending", "As a distance from", "URL parameter", and "toolset_maps_distance_center". See Screen Shot 2018-12-18 at 4.42.29 PM.png
- In the Loop editor, you can insert a shortcode that displays the distance between each result and the toolset_maps_distance_center. The format looks like this:
[toolset-maps-distance-value origin_source='url_param' postmeta='wpcf-book-location'] miles from [wpv-search-term param="toolset_maps_distance_center"]
- See option-2.png and option-1.png. You can see that option 2 has fewer input fields. Option 1 has more input fields, but the distance calculations are more accurate because the User must select from the autosuggest locations.