Home › Toolset Professional Support › [Resolved] All Items on Map on Initial Load & Refresh with Paginated Grid Items
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.
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)
Tagged: Custom search, Toolset Maps, Views plugin
Related documentation:
This topic contains 24 replies, has 2 voices.
Last updated by Nigel 5 years, 6 months ago.
Assisted by: Nigel.
I'm looking to have all items populate on the map initially on the archive with filters & a grid view with photos but limit the amount of items on the grid. There will be over 400+ listings and the issue with pagination or infinite scrolling is that on each page view only the displayed items per page show up on the map. So when you initially go to the listings page, it looks like there are only "x" amount of listings since its populating the "x items per page" when in reality there are hundreds of listings.
Is there a way to still show the filtered results on the map, but on resetting the filters & on initial load show all items? I know it could be set up with 2 different pages, but was wondering if it was possible to have this setup in the archive view.
Thanks!
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
The basic problem here is trying to use a single database query to generate two different sets of results.
If you include pagination then the database query only returns as many results as are set to display on a page.
You can do more than one thing with that set of results—display links to the posts and plot the posts on a map—but each of these is working from the same set of results.
What you describe—showing all results on the map but only a subset of results in the list (or grid) of posts—requires two different queries, one query to get all results for the map, a second query for the paginated list of posts.
You can manage this simply enough by generating your list of posts with a custom archive (it sounds like you are working with a post archive) but generating the map with a View that you insert into the custom archive template.
But then your map markers become disconnected from your list of results. If you add a search filter to the archive (which outputs the list of posts) and apply that filter, your list of posts would narrow but your map would be unaffected.
You can resolve that problem by
- including the search filters (plus pagination) in the custom archive. Make a note of the URL parameters that will be used for the filters.
- in the View that generates the map add Query Filters for the same fields and/or taxonomies where the value comes from a URL parameter, and use the same parameter as is added by the custom archive search
You might insert this View in between the wpv-filter-meta-html and wpv-filter-layout-html shortcodes in the Output Editor of the archive, for example.
A limitation is that your custom search in your archive must work via a submit button and page reload. If the page does not reload then only the archive is updated, the View (the map) wouldn't update, but when it does it will see the same URL parameters and change the results returned in the same was as the archive that lists the posts.
Thanks Nigel, I appreciate the detailed response!
Unfortunately, the limitation of losing ajax with live filtering / needing to have a submit button is something that is necessary. Having the results populate without reloading the page / needing to click submit is a client request.
Just for an example, this is a similar setup looking to replicate...hidden link and hidden link.
Is there any way to replicate this setup with toolset and still using ajax live filtering? From your detailed response, it looks like it may hinge on using a submit button instead. This obviously wouldn't be an issue if all listings could be loaded on the page, but with the sheer amount that would require a very long load time for the page.
Wanted to double check, any other suggestions?
Really appreciate the help & guidance.
Thanks!
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi Aaron
I've given it some more thought, and I can't see a way past the limitation requiring a page reload I described above, because of the need to run two queries when you want to display both paginated and non-paginated results.
Unless...
thinking aloud, without trying it, you could set both Views up (you will still need two Views, one for each query) so that they included the same search filters and both updated via ajax.
You wouldn't want both sets of filter controls to appear on screen, and you would hide one set with CSS.
Functionally you effectively need to "click" both filters, one straight after the other, which would trigger both View results to update via ajax.
So you would need to add some custom JS that listened for events on your visible set of filters and programmatically triggered them on the corresponding hidden filters.
It's a little bit hacky and will require a custom code solution, but it's the only way I can think you would be able to achieve this without using a page reload.
Appreciate you taking some time to think through a solution Nigel.
I know with custom code that's usually beyond the support realm, but is there any insight where I could possibly try and test out the solution using custom JS that listened for events on the visible filters / trigging the hidden filters.
I set up the separate views and have hidden a filter using custom css, and would like to give it a go to see if it would work.
As I mentioned, the problem of only showing a limited number of listings is that it looks like there are only x listings listed...when really there are hundreds of listings. I would think there would be similar users out there who would need the same setup / map with all markers without having all grid items shown on initial load which would take a long time to load.
Any direction for the JS events would be greatly appreciated, thanks again!
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
I have a test site where I can try and put something together, but it will likely be in the morning now, I'll let you know.
Great, thanks a lot Nigel, much appreciated!
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
To recap, I have one View (with filter controls and pagination) that lists the posts, and a second View (with filter controls but no pagination) that displays the markers on a map.
I'm going to add some JS so that whenever a filter control from the first View is changed it will perform the same change to the matching filter control in the second View. CSS can be used to hide the second set of filter controls.
First, I need to add classnames to the filter control sections of each View so that I can target them with JS (actually jQuery).
When editing the Views scroll down to the Output Editor and add a wrapper div around where the filter controls are inserted, e.g.
<div class="visible-controls"> [wpv-filter-meta-html] </div> [wpv-layout-meta-html]
I use the classes "visible-controls" and "hidden-controls" in my test example.
Now add the following JS to the custom JS editor of the Search and Pagination section of your first View with the visible controls.
(function ($) { $( document ).on( 'ready js_event_wpv_parametric_search_results_updated js_event_wpv_pagination_completed', function( event, data ) { $('.visible-controls select[name="wpv-colour"]').change( function(){ var current = $(this).val(); $('.hidden-controls select[name="wpv-colour"]').val( current ).change(); }); }); })(jQuery);
The first thing to note is the $(document).on() section. We are adding this code on the DOM ready event (i.e. when the page loads), but we also have to add it back again after any ajax update because of a search or pagination, using the two custom JS events provided by Views for that purpose which you can see in the code).
You don't need to touch that.
What you do need to touch is the next part.
My test site has just one filter control, a dropdown select field which I can inspect with my browser dev tools to see it can be targeted with name="wpv-colour".
So the code listens for a change in the select field and when that happens takes its value and updates the matching select field from the hidden filter controls (and triggers the change event on that field).
You will have to do something similar for each of the filter controls in your search.
Thanks Nigel! I've set up the views and included the JS / div information that you referenced.
I was able to get the basic functionality to work, however, the results are quite spotty in terms of filtering on the map. Some specific items on the filters will load the map, other times the map will be stuck be on "map is loading..." and sometimes it won't show up at all.
To troubleshoot, I added the js-wpv-addon-maps-reload-map button that will then render the map when clicked on the results if nothing shows up, so it seems like the map loading is getting stuck.
How would I go about doing this similar function used for the filters for the search box & reset filter buttons? I'd like to get it all replicated and then troubleshoot further. I'm guessing the JS is different for text search & reset button.
The biggest issue I've found as well, since using it with the divi builder, is the style gets all messed up on the grid once the ajax filtering is used. If I used a page with the view without the divi builder the styling is ok for a while, then eventually gets messed up. It looks like the footer styling (which is used with the divi builder) is getting mixed up in the grid styling. I know this is a known issue with the divi builder + toolset...but it doesn't seem to happen using the wordpress archives, just on views within the builder. Is there a way to fire the JS for the divi footer item on ajax filtering so that the style doesn't get messed up?
Thanks!
Nigel, I was able to figure out the reset filter as well as the submit & search using JS. I used keyup functions for typing & click functions for the reset & submit buttons.
The only issue with search was when the enter key is pressed without tabbing or clicking the search button it wasn't being duplicated so I used keypress function (if key=13) to return false on initial use of the enter button until either tabbing or clicking on the search icon button.
I'm still running into some filters not loading anything on the map...it gets stuck on loading. However, if I refresh the page / clear cache it loads.
And the styling gets broken as well, as I mentioned in the previous post. If I enable caching within the view settings or include cached=off" in the view shortcode, it breaks styling of the grid entirely the minute an ajax filter is triggered. It basically picks up styling of the footer or header on that page (with divi builder enabled). Is there a way around this issue?
Again, I don't run into the builder / divi styling breaking with the same content template setup in the WordPress Archive View, just when creating views and adding them via shortcode on the page.
Thanks again!
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi Aaron
Sorry, I wrote a reply yesterday afternoon but I don't see it, it seem lost.
I had checked with the developers about the appropriate JS event for the text search field, and they had confirmed that the field listens for the keypress event for key=13, so that's what you need to trigger on the hidden filter.
To trigger it you can try something like this:
var fakeEvent = jQuery.Event( 'keypress' ); fakeEvent.which = 13; $('input[name="wpv_post_search"]').trigger( fakeEvent );
As far as the styling issue with Divi goes for ajax updates, I think you are caught up in this issue: https://toolset.com/errata/posts-designed-using-divi-builder-will-not-display-in-an-a-view-that-uses-ajax-pagination/
That includes a workaround using the suppress_filters attribute. Could you try that?
Hi Nigel, no worries at all. Appreciate the response back.
For the trigger, is this part of the previous function you included or is this standalone? Wasn't sure if this went in the "visible" view or the hidden view search and pagination JS editor.
I'm still running into issues with the two views, sometimes the map won't show up at all or it will be stuck on "map is loading...", it seems like certain filters cause these actions to happen. The query filters are the same on both views. If I refresh the page (on the browser and not the ajax refresh button) the map & grid load fine.
Unfortunately, the suppress_filters attribute isn't solving the issue of the style / layout breaking with Ajax and Divi. If I use the divi builder on the page to add the views shortcode, it breaks the style immediately on any ajax action. However, if use the standard WordPress editor on the page and insert the shortcode, it only breaks the style here and there, but it still breaks. The content template itself for the view was built with the builder.
This doesn't happen on the WordPress Archive View with the same divi content template layout. And I don't run into any map issues using he Archive view, it always populates & loads.
At times, for the styling, it seems like a caching issue but other times it doesn't. If I refresh the page manually on the browser, the map & grid load fine. However, if I then hit the ajax refresh button, the style breaks.
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Hi Aaron
That JS snippet was just an example of how to trigger a keypress event for a particular key (13), which is trickier than simply apply .change() to a select dropdown. You would need to listen for the keypress event on the first filter control and then trigger it on the second.
The rest of your question seems to reflect two issues:
1. problems with the map refreshing via ajax
2. problems with the Divi styling being broken
For 1. I would test with your custom JS and any CSS to hide the second filter control section removed, so that you can see both sets of filter controls for each View. Try manually changing a filter in the first View and then straight away changing the same filter in the second View. Are you able to reproduce the problem in this scenario where it is just you clicking on filters? If not, there's a problem with the coded solution we are trying. Maybe a very small delay would help.
For 2. I'm going to set up a somewhat generic test on a Divi site to reproduce the issue and see what I find. I'll post another update.
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
I'm struggling to reproduce the problem with Divi styling.
I have a page designed with Divi that has a couple of columns, one of which has some static content, namely an image, with some custom styling applied, the other of which has a View inserted.
This View includes search filters and pagination controls, with updates happening via ajax. The output of the View is via a Content Template, and this template is designed with Divi, which also includes some custom styles.
(The posts themselves are not designed with Divi, but then as my View doesn't output the post body of those posts that doesn't seem relevant.)
Visiting the front end and updating the View (either paginating or searching) doesn't affect anything other than the output of the View itself.
Am I missing something?
Nigel, really appreciate the detailed response.
1. When I enable both filters on the combined view page, the "hidden" filter works flawlessly with the map, no loading issues. When I use the "visible" filter for the grid, it works as well. I can also see that when clicking on the "visible" filter, the "hidden" filter is showing the same filters being chosen. So each filter is working by itself fine, the issue seems to be with the coded solution getting hung up at times. Sometimes the map is coming up, other times its not at all and I notice on the google inspector that its coming up as "display; none" at times for the map even though I don't see any css to hide the map. Any chance you could take a look at the backend of the views / JS to see if there's something wrong? I don't see any console errors.
I'd really like to try and make it work, as having all the pins on the map load is essential to make sure it doesn't look like the listings are limited to the page load number.
2. The divi styling issue seems to be related to cache and the builder. If I turn caching on the view for the listing grid and don't use the divi builder for the page, it seems to be happening very infrequently. However, if I use the builder on the page the styling breaks immediately when hitting the ajax refresh button or any filters. I do have an echo do_shortcode for a builder section in the footer in my child theme folder, but removing it didn't seem to change anything.
I had a similar issue with repeating fields and views within the content templates, with the style breaking whenever I would delete a repeating field on a post. To solve that issue I found out disabling "static css file generation" within the theme options was causing the issue, which I found through another toolset support post.
Thanks!