Home › Toolset Professional Support › [Closed] Split: Map Questions – show no results until select filter
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.
This topic is split from https://toolset.com/forums/topic/map-questions/
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | - |
- | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | - |
Supporter timezone: Europe/London (GMT+00:00)
This topic contains 27 replies, has 3 voices.
Last updated by Nigel 1 year, 2 months ago.
Assisted by: Nigel.
I see where you added it. The search page for that post type. On the page where you added it (please don't post publicly) even if I clear the filters, it's still showing map markers for the ten locations below the map. How do I set it up so
1. It's a blank map of the US when the page loads
2. No search results pre-load. I have no idea why those ten items are appearing when you load the page?
How can it possibly be this complicated to simply set a default location on the map?
Hello. Thank you for contacting the Toolset support.
Can you please share information with what view you want to display only filters and do not display the result until the filter is selected. is it with the same view? or you can share the problem URL of your view.
I have set the next reply to private which means only you and I have access to it.
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi there
Minesh is on vacation, so let me jump in here.
I was just checking on my local test site about how to set a default location when there are no markers to display, and I'm struggling to see how to do it when working with the block editor. I'm over the end of my shift so I'll look again in the morning with fresh eyes and I'll get back to you with a solution.
You say you don't understand why there would be results on a page before someone searches, but that's because the search fields operate as filters, rather like narrowing down results in Amazon as you apply more filters rather than expanding out from nothing like Google.
In any case, I'll update you again in the morning.
Thanks. It seems to me like...even on Amazon, I don't expect to see results for blue shoes if I didn't ask to see blue shoes. I want it to be a blank slate for someone to put in what they want.
If it can't be like that, maybe we could start it with a filter like "only x custom field value". How would I do that? I can think of a custom field say wpcf-field-name, with "large" and "medium" as two of it's options. How would I set it to load just those things on page load before a search is entered?
That could be one option but I'd prefer it if it could be a blank map with the search filters below it and let them choose what they are looking for rather than be presented with things that have nothing to do with what they are looking for.
Right now it's just scrolling through every one of 20,000 items which makes no sense and is a terrible user experience in my opinion. Amazon doesn't give me some random bunch of results then rotate them every 5 seconds. It gives me categories to choose from and the ability to search. But until I do so, I'm not getting random results for things I never asked to see. Somehow in my example it's starting with items that start with M for no reason I can see. Who asked for M's? No one.
And what setting is making it keep rotating to a different result on it's own?
Thanks, Nigel.
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
OK, I managed to recall how to set the default map location when there are no results. (It's not intuitive, and we at least need to document this, I'll create a ticket for the documentation team when I'm done here.)
Where you have a View that generates the results for a map, to set a default location for when there are no results to display you must provide lat and lon coordinates for the desired map centre. And to be able to enter those you must
1. temporarily disable the setting "Adjust zoom and center to show all markers at once" (screenshot 1)
2. enter lat and lon coordinates (screenshot 2)
3. re-enable the setting and save the page
Now when there are no results to display the map should centre on your desired location, and not off the coast of Africa.
Next, the question of no initial results.
Ordinarily this is fairly straightforward, where you don't want the output of a View (the unfiltered list of results) to display until a filter value has been chosen, and it is explained in the documentation here: https://toolset.com/course-lesson/creating-a-custom-search/#hide-the-search-results-until-the-first-search
The complication in your case is that you are not just outputting a list of results with the View, but generating the markers on the map with this same View. In the solution above the View query returns the unfiltered results, but using the conditional block these are not output on the screen unless some filter has been applied. But the query returns results, and these are being passed to the Map block to generate the markers.
The only way to prevent the markers being created before a filter has been applied is to modify the query generated by the View so that there really are no results returned (rather than the results effectively being hidden).
We can do that using the Views API hook wpv_filter_query_post_process. Add the following code to your site (you could add it to your theme's functions.php or add as a code snippet at Toolset > Settings > Custom Code):
/** * No initial results * * Don't show View results until a filter has been applied * * Tests for custom field filters, taxonomy filters, text searches, or maps distance filter */ function tssupp_no_initial_results( $query_results, $view_settings, $view_id ){ $target_views = array( 123 ); // Edit to add IDs of Views to use this with if ( in_array( $view_id, $target_views ) ) { // is there some 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_center'] ) ) { $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 );
You will need to edit the ID of the View you want to apply this to ("123" in the example). Note, finding the View when using the block editor is not so obvious. Go to Toolset > Settings and under "Editing experience" choose the option to show both block and legacy UIs. After refreshing the page, you should then be able to go to Toolset > Views and see a list of Views on your site together with the View ID, which is what you need to edit in the above code.
So, on the basis of that code together with the map tweak above, when you first arrive at the page there should be no results shown, and the map should be centred where you intend.
As for the continuously updating results you currently have, that would be because of your pagination settings, which are effectively set to work like a slider, rotating the results every 5 seconds (screenshot). You presumably want a manual pagination setting.
Nigel,
Thank you for that detailed reply, I really appreciate it. I'll give it a try now.
Question:
How would I set the initial view to display a particular value like..."on initial load, show all with custom field "size" = Large and Medium?
Thanks again.
It works! Thank you!
In this part of the code, what does the 10 and 3 represent? Would I change one of these to zoom it in a bit more to start? I tried changing 10 to 8 but it didn't make any difference. The map settings in the block editor don't seem to change it on initial load either.
Another question, search results are quite slow. Do you want me to open a separate ticket to look at that?
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
I see you opened another ticket about the search speed, I've replied to that.
You were asking here about the 10 and the 3 in the code, they relate to the priority of the callback function added to the filter (smaller numbers mean the code runs sooner if there are multiple callbacks) as well as the number of arguments passed to the function (in this case 3).
What you are looking for is to change the zoom setting of the map? When markers appear in the results the zoom is set automatically. When there are no markers and you use the technique I described above to specify the map centre, the zoom level is set by the "ZOOM LEVEL FOR MULTIPLE MARKERS" setting. (I know, that is not clear, but that's what I found just testing it now.)
Hi Nigel,
That page with the map view was the one where the view was mysteriously broken so I had to create a new one.
On the new one, I'm back to the default map view with no listings not working It's really strange. I did the steps you outlined above, as I did last time, and it keeps giving me china/Tibet. If I google lat long center of US I get
37.0902° N, 95.7129° W
If I put that in the lat long, it gives me china.
Can you look and see what I'm doing wrong? I did update the view id in the snippet. I disabled the zoom thing, added lat long, re-added it, and it's still china. Not Africa, but somehow it's not reading lat long? Or I'm putting it in wrong? Can you look? The link is the same as it was, in the private message, I'll add it to the top to make it clear.
Thanks
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
I just checked on Google Maps and it returns these coordinates for the USA:
35.7032076,-116.922443
Note that longitudes west of zero (Greenwich, London) have negative values. In your case if you used a longitude of 95.7129 that is east of London, which I guess takes you to China.
(You may want to tweak those coordinates depending on if you are happy with exactly where in the USA it centres the map.)
Nigel,
1. on that same maps page (in the private reply)
Secondary sorting is really limited. How would I get secondary sorting to give me the same options as first level sorting?
Can there be a third level of sorting?
For example I want custom fields:
State
City as an example.
The options don't let me do that.
2 same map page, how would I create/apply custom markers for different things?
> Different post types on the same map
> Different custom field searches > different map markers
3. I see how to add custom markers, but how do you make different markers show up on the same map for different things? Every other map solution I've tried offers this...I don't see it here? It looks like you can only choose one map marker for the whole map, be it one of the standard ones or one you upload? That can't be true, I must be missing how to add different markers for different things? I tried adding a second CPT to the map but that didn't change marker selection. Surely you can use different markers to show different things on the same map?
4. The map block on the page in edit mode doesn't show a map. It used to. This map/view thing keeps behaving strangely. Having to redo the whole thing has been a pain. The fact that it just broke with no way to know why really worries me about being live with it.
5.
Ah duh, sorry my bad, I was using the other format for lat long which when you google it is what you see everwhere. Got it thank you 🙂
There is something going wrong with that page again. I have a fast enough connection. Every other page I load both on that site and elsewhere loads normally. But that map page, spins and spins and same with the front end of it. It's doing something weird. I've closed out of it now, I give up for now. Can you see if you load both the admin end and the front end if you get some errors or see what's happening? I'm just trying to adjust the zoom level on the map but it just will not load all the way, blocks keep saying that can't load, and only for that page. Weird.
And I put lat long in but it got zeroed out. That page just continues to behave really badly. Do I have a setting or something that is wrecking it?
The topic ‘[Closed] Split: Map Questions – show no results until select filter’ is closed to new replies.