Skip to content
Advertisement

Make AJAX Pagination work with (AJAX) URL filter parameters on refresh

I have a well defined AJAX filter, in two parts, one for a load more button, and one for a selection of drop down filters. Both reload a list of properties on the front-end in AJAX, and work together in unison (e.g. If I select Min price, max price and number of beds in dropdowns, the list refreshes, and the load more button works as it should).

The same filters also work with URL parameters. So for example, if the URL was:

JavaScript

It would filter by those parameters. It even shows 3 pages worth of properties as it should. This works great, including on initial load. However, it does not work with the pagination, IF the URL is loaded directly. If I enter the above URL directly into the browser, and load, the initial results are correct, but on clicking the Load More button, it changes page=3 to page=4 (correct) but it append’s the second page of properties completed unfiltered, and continues to do so – rather than carrying on the filtered pagination.

What am I doing wrong?

Here’s my code (sorry it’s a lot!)

JS:

JavaScript

Functions.php :

JavaScript

and the HTML:

JavaScript

Advertisement

Answer

In the end, I solved this myself. The way I did it was by passing the URL params into variables before the loadmore AJAX ran, something along these lines

JavaScript

This then made the REQUEST work on ajax call on click of the load more button

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement