0
votes

I'm using wp_query with pagination to load a lot of posts with a custom developed infinite scroll jQuery plugin I made, it takes sometime to load 20 post with thumbnail images and inject them in the DOM everytime the plugin request a new page.

I thought if I can reverse the pagination direction so that page 1 shows the oldest 20 posts (not the recent 20), then the second page shows the next 20 old posts and so on, then I can cache the requests of those pagination links it would make the performance much better.

This way page 1,2,3... should always return the same posts, and the latest page should have the most recent posts.

Does this make any sense? and how can I do it?

1

1 Answers

1
votes

Order your posts by date:

WP_Query(array(
    ...,
    "orderby" => "date",
    "order" => 'DESC',
    ...
));

Then force the requested pages to be cached by the browser with jQuery:

$.ajax({
    url: ...,
    type: "GET",
    cache: true,           
    ...
});

Here's more information about the cache parameter in jQuery: https://stackoverflow.com/a/18671689/1123556