Forum
User filtered products combined with categories and pagination
I've used the article here: https://docs.grabaperch.com/perch/content/functions/user-filtered-lists/ (with some modifications) to add the ability for a user to filter products by category using checkboxes. This works great.
I have a lot of products so I'm using pagination to show products in chunks of 60 in my case. This also works great.
However, when I have a filter selected and I select to load the next 60 products (i.e. page 2) I am running into issues with the pagination not respecting the filter, it currently just returns the next 60 products regardless of the filter applied.
When filtering a category my url looks something like this /products?category=categoryName
.
When selecting the next page with a filter applied I have tried this /products?page=2?category=categoryName
. However it returns products outside the filtered category. You can see it in action here: https://www.chase-erwin.com/fabrics if you select the White/Cream/Beige 'Colour' filter then scroll to the bottom of the list and click 'Load more' then you will see the next set of products clearly aren't all White/Cream/Beige. (All requests are handled via ajax)
Is it possible to combine user filtered content and paging?
What can you tell us about how you're putting your links together?
I have a
get-products.php
page which I call via ajax to getperch_shop_products()
with any filters applied.The ajax url is
/get-products?' + $('#form1_fabricFilter').serialize();
My
get-products.php
page looks like this:The paging template is this:
Then I use jquery to count the number of times the Load more button is clicked and increment a
var pageNumber
variable so I can pass it to theget-products.php
page again using ajax.With the page number added, the url looks like this:
/get-products?' + 'page=' + pageNumber + '?' + $('#form1_fabricFilter').serialize();
You can't have two
?
chars - the second needs to be an&
instead.Oh man, how did I miss that! Thanks so much, has been plaguing me for a while