I am using a custom query in order to ajax load/append additional posts instead of paginating them out like WP defaults. However, when I click the button I've made to load more posts, it loads all posts rather than the ones that match the search result (while the first set matches the search result). How do I maintain this format of loading posts while retaining the search query?
I successfully did this for my category pages with something like query_posts(array('cat' => $category));
but am unsure how to do it for search.
Button:
var pager = 1;
var search_load_posts = function(){
$.ajax({
type : "GET",
data : {pageNumber: pager, offset: 12},
dataType : "html",
url : "http://tay.is/designing/belmontvision/wp-content/themes/yamidoo/search-more-loop.php",
beforeSend : function(){},
success : function(data){
var $data = $(data);
$container.append( $data ) .packery( 'appended', $data );
heightcalc();
$container.packery();
}
});
};
$('.search-load-more').click( function() {
search_load_posts();
pager++;
});
Original Loop Query:
<?php if (have_posts()) : get_template_part('loop-search'); ?>
Top Loop Search (loop-search.php):
<?php $count = 1; while (have_posts()) : the_post();?>
Additional Post Query (search-more-loop.php):
<?php require_once('../../../wp-load.php');
$page = (isset($_GET['pageNumber'])) ? $_GET['pageNumber'] : 0;
$offset = (isset($_GET['offset'])) ? $_GET['offset'] : 0;
$args = array ( 'posts_per_page' => 12,);
$last_twelve = get_posts($args);
$last_twelve_ids = array();
if( $last_twelve ) foreach( $last_twelve as $last_post ) { $last_twelve_ids[] = $last_post->ID; }
query_posts(array(
'paged' => $page,
'post__not_in' => $last_twelve_ids
));
while (have_posts()) : the_post(); ?>