next_posts_link not working for loop called with ajax

next posts link is somewhat pointless since you’re paginating with ajax, no? have a look at the code from the answer to your other question at how I paginate the query-

var postoffset = $('.post').length;

that counts how many posts are on the page and then I pass that as the offset. in your case it would be .box. when I put that in the query, I get back posts starting at that number:

$offset = $_POST['postoffset'];
$args = array(
    'offset' => $offset,
    'posts_per_page' => 10
);
$wp_query = new WP_Query( $args );

that way I can just use the same button to load more posts, it just repeatedly calls the same function, checking how many posts are on the page each time.

Leave a Comment