Skip Navigation

[Resolved] View Distance Filtering: Max Radius and Default Location

This support ticket is created 2 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 6 replies, has 2 voices.

Last updated by zacharyL 2 years, 3 months ago.

Assigned support staff: Minesh.

Author
Posts
#1801821

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

#1802709

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

There is no such feature to restrict the radius to maximum 25 miles but we can workaround this by adding some JS so this could be easily achieved.

Regarding the filling out the location field with current user location, there is no such feature and even if we try to use some JS, user first require to be agree to get his location so we can not auto-fill the location field with current user location. The workaround for that is we can add some JS and until user do not add the location text we can disable the "Submit" button.

Please let me know whats your thoughts on this.

#1803243

I think I can figure out a way to use jQuery to make the location field "required" with logic that dictates "if location field is empty, preventDefault() on the submit button." That makes sense.

Not sure how I would be able to make a maximum numerical value in the radius field, however.

I also need to make sure Toolset's AJAX functionality isn't going to clear out my event handlers, because I've had that happen in the past.

#1803963

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

As per our support policy we entertain only one question per ticket. You should create a new ticket for every new question you may have.

I will address here the max radius and default location issue.

So, to restrict the radius field, you can add the attribute max="25" using the JS targeting the radius field.

I hope that will solve the issue.

#1806381

I think I can handle that. I will keep you posted if I can get it to work.

Regarding your other comment, I don't see how my comments suggest I was inquiring about anything outside the original scope of my initial inquiry. If Toolset's AJAX interferes with my jQuery's event handlers, I will open a new ticket, if that's what you're concerned about.

#1807909

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Please let me know if you will require further assistance.

Regarding your other comment, I don't see how my comments suggest I was inquiring about anything outside the original scope of my initial inquiry. If Toolset's AJAX interferes with my jQuery's event handlers, I will open a new ticket, if that's what you're concerned about.
==>
Ye - it could be. So, kindly open a new ticket with your every question you may have. This will help other users searching on the forum as well as help us to write correct problem resolution summery for your original question.

#1819385

jQuery solves my problem. Thank you.