Hacking ‘posts_per_page’ in WP_Query

Here’s some options:

Keep The AJAX

You drop out your posts_per_page => 15 query and keep the -1 query. Then after your map loop ( or before ) you can limit the amount of items showing using a counter:

if( $map->have_posts() ) : $counter = 1;
    while( $map->have_posts() && $counter <= 15 ) :
  ?>
    ...
  <?php
    $counter++;
    endwhile;
endif;

You could then use $map->rewind_posts() respectively. Now the AJAX portion you would requery the results but since it’s not happening during page-load you’ll see a speed increase. You then just offset => 15 and posts_per_page => 15 so it’s a faster query, return results and append or replace what you currently have in the results section.


Simple Hide / Show

In this scenario you would want to use the rewind_posts() mentioned earlier. Pretty much you would loop through all the results putting them in <div>‘s of 15 ( I suggest using modulus to test this. You can then use jQuery to process when the user clicks “next” to show the next div which has a set of 15. Since you’re only using 1 query the page speed will be based on the looping which will turn out to be fairly quick.