I have a couple views that work in tandem that act as a directory of distributors. One view outputs map markers on a Toolset map, while the other spits out a list of locations underneath the map. Both are beholden to filters that the user can utilize to find distributor locations near them. There is a distance filter that allows the user to input a location and the radius (in miles) around that location, as well as a taxonomy filter and a custom field filter.
The client has requested that the distributor locations be hidden initially, and should only reveal the distributors once a user inputs a filter input. On top of that, they would like the distance radius to be limited to a maximum of 25 miles and the location field to either be required or be populated with a default location.
I was able to hide the view output with the help of a support thread, with this solution:
/**
* No initial results
*
* Don't show View results until a filter has been applied
*
* Tests for custom field filters, taxonomy filters, or text searches
*/
function tssupp_no_initial_results($query_results, $view_settings, $view_id) {
$target_views = array(1995, 2004); // Edit to add IDs of Views to add this to
if (in_array($view_id, $target_views)) {
// if there is a search term set
if (!isset($query_results->query['meta_query']) && !isset($query_results->query['tax_query']) && !isset($query_results->query['s']) && !isset($_REQUEST['toolset_maps_distance_radius']) && !isset($_REQUEST['search'])) {
$query_results->posts = array();
$query_results->post_count = 0;
$query_results->found_posts = 0;
}
}
return $query_results;
}
add_filter('wpv_filter_query_post_process', 'tssupp_no_initial_results', 10, 3);
...but I can't seem to find any solutions on the other two requests.
The client has requested this change because their competition have started using this distributor directory as a means to steal away their clients, the ones who purchase their products wholesale to sell in stores. However, they still need the directory for the average customer to find one of those stores that sells their products.
As it stands, without having a maximum radius or requiring the location field, a user can simply hit the submit button, without filling out any fields, and the view spits out all the posts, thereby bypassing the reasoning behind hiding the posts in the first place.
Is there anything that you can help me with in this area?
You can find the views on this page here: hidden link