Forums › Forums › Search & Filter Pro › Filters in slideout sidebar not working
- This topic has 7 replies, 3 voices, and was last updated 3 years, 11 months ago by Trevor.
-
Anonymous(Private) December 8, 2020 at 3:03 pm #269113
Hi!
I have a list of cpt shown created with Wp Show Posts plugin on this page: https://saveursducanadaeurope.com/importateurs-distributeurs/. When I use Search and Filter Pro on the sidebar the filters work perfectly. To make it work I had to use the custom display result method option and add the shortcode with action=”filter_next_query” next to the list of posts.
In this other test page: https://saveursducanadaeurope.com/test/ instead of putting Search and filter pro in the sidebar I have put it in a slideout. Just for that reason it seems that it stops working. There is also no javascript error. If on the test page I remove the slideout and put the Search and Filter Pro shortcode back into the sidebar then the filtering works again.
This is the javascript code that shows the slideout sidebar:
<script> (function($) { window.FWP = window.FWP || {}; window.FWP.flyout = { open: function() { FWP.flyout.swap_facets('open'); }, close: function() { FWP.flyout.swap_facets('close'); }, init: function() { var content = ''; var flyout = ` <div class="facetwp-flyout"> <div class="facetwp-flyout-close">x</div> <div class="facetwp-flyout-wrap"> <div class="facetwp-flyout-content">[searchandfilter id="1077"]</div> </div> </div> <div class="facetwp-flyout-fog"></div> `; $('.facetwp-flyout').remove(); $('.facetwp-flyout-fog').remove(); $('body').append(flyout); }, swap_facets: function(action) { var action = ('undefined' !== typeof action) ? action : 'open'; var is_open = $('.facetwp-flyout.active').length > 0; if ((is_open && 'open' == action) || (!is_open && 'close' == action)) { return; } // Add the open or close CSS class $('.facetwp-flyout').toggleClass('active'); $('.facetwp-flyout-fog').toggleClass('active'); } }; $(function() { FWP.flyout.init(); }); $(document).on('click', '.facetwp-flyout-open', function() { FWP.flyout.open(); }); $(document).on('click', '.facetwp-flyout-close, .facetwp-flyout-fog', function() { FWP.flyout.close(); }); })(jQuery); </script>
Any suggestions on how to make the filter work in the slideout?
Ross Moderator(Private) December 9, 2020 at 2:57 pm #269279Hi there
I think inside the
init
after$('body').append(flyout);
you need to add:$( '.searchandfilter' ).searchAndFilter();
Because the html is not in the dom the page on page load, our scripts don’t initialise it, so it would need initialised after the html had been added to the DOM.
Let us know how you get on.
Thanks
Ross Moderator(Private) December 9, 2020 at 2:59 pm #269283Also, if you want to do stuff before / after search results have been fetched, you can use the
sf:ajaxstart
andsf:ajaxfinish
events:Anonymous(Private) December 9, 2020 at 5:23 pm #269325Thank you Ross,
The solution you gave me works perfectly.
Now I have found another inconvenience. I only activate the slideout with the Search and Filter Pro filters in the mobile version < 768px wide here: https://saveursducanadaeurope.com/importateurs-distributeurs/
For the desktop version I use in the sidebar the same Search and Filter Pro shortcode as in the slideout but I hide it by css in the mobile version.
So in mobile version you only see the filters of the slideout but the results are affected by the filters not active in the sidebar that is only hidden by css but remains working.
Is there any way that in resolutions of < 768px I can disable the shortcode of the sidebar and activate the slideout or some other way to combine both in the same page but without interfering?
Ross Moderator(Private) December 10, 2020 at 4:08 pm #269451Hi again
Hmmm.. its tricky, right now we don’t support both (duplicates) on the page at the same time due to this issue (we will in v3, due early in the new year)
So there are two workarounds:
1) Don’t add S&F to the sidebar via a widget, instead, add it with Javascript on page load (like you did with your slideout, only in that case, after a click), so you can conditionally add it to the sidebar if viewport width >= 768px
2) Create a seperate search form + results for mobile onlyI hope that helps
Best
-
AuthorPosts