Paginate pages with dynamic query

I was going to create my own question and answer it, but this looks as good a place as any. The way I solved this, is by using $_SESSION. Keep in mind I am using infinite-scroll, so I can tell when the page is being fetched via ajax as opposed to being actually navigated to in the browser.

So here’s the steps/pseudo-code:

  1. Clear Session Variables
  2. Run “Default” loop and get html
  3. User filters results -> get results from new loop
  4. Set Session Variables so page knows which loops to run
  5. User scrolls down -> get results from current page, but for next page
  6. This page displays a loop conditionally based on the session variables
  7. ??????
  8. Profit

I would just post my code, but it is pretty large so I’d rather not. If you can’t figure it out, let me know though and I will post the skeleton of the code.