I have a function that dynamicaly loads more posts after clicking the button and a LoopHandler.php that is displaying posts. Everything works perfect, apart from that the loop is always displaying all of the posts. So if I am on the category page it displays posts from all of the categories. Why is it happening so? How to fix it?
// ajaxLoop.js
jQuery(function($){
var page = 1;
var loading = true;
var $window = $(window);
var $content = $("body #post-stream .block");
var load_posts = function(posts, row){
$.ajax({
type : "GET",
data : {numPosts : posts, pageNumber: page, postsInRow: row},
dataType : "html",
url : "../loopHandler.php",
beforeSend : function(){
$content.append('<div id="temp_load" style="text-align:center; clear: both; padding: 30px 0;">\
<img src="http://cayennestudio.pl/segritta/wp-content/themes/segritta-ajax/css/img/ajax-loader.gif" />\
</div>');
},
success : function(data){
$data = $(data);
$(window).scrollTop($(window).scrollTop()-1);
if($data.length){
$data.hide();
$content.append($data);
$data.fadeIn(500, function(){
$("#temp_load").remove();
loading = false;
});
} else {
$("#temp_load").remove();
}
},
error : function(jqXHR, textStatus, errorThrown) {
$("#temp_load").remove();
alert(jqXHR + " :: " + textStatus + " :: " + errorThrown);
}
});
page++;
}
var load_szorts = function(posts, row){
$.ajax({
type : "GET",
data : {numPosts : posts, pageNumber: page, postsInRow: row},
dataType : "html",
url : "http://cayennestudio.pl/segritta/wp-content/themes/segritta-ajax/loopHandlerSzorts.php",
beforeSend : function(){
},
success : function(data){
$data = $(data);
$data.hide();
$content.append($data);
$data.fadeIn(500, function(){
loading = false;
});
},
error : function(jqXHR, textStatus, errorThrown) {
alert(jqXHR + " :: " + textStatus + " :: " + errorThrown);
}
});
page++;
}
if ( $('body.home').length ) {
load_posts(4, 2);
$('.load-more').click(function(){
load_posts(4, 2);
});
};
if ( $('body.category').length ) {
load_posts(9, 3);
$('.load-more').click(function(){
load_posts(9, 3);
});
};
if ( $('body.post-type-archive-szort').length ) {
load_szorts(8, 4);
$('.load-more').click(function(){
load_szorts(4, 4);
});
};
});
LoopHandler.php
<?php
// Our include
define('WP_USE_THEMES', false);
require_once('../../../wp-load.php');
// Our variables
$numPosts = (isset($_GET['numPosts'])) ? $_GET['numPosts'] : 0;
$page = (isset($_GET['pageNumber'])) ? $_GET['pageNumber'] : 0;
query_posts(array(
'posts_per_page' => $numPosts,
'paged' => $page,
));
global $var_counter;
global $var_row;
$var_counter = 0;
$var_row = (isset($_GET['postsInRow'])) ? $_GET['postsInRow'] : 2;
// our loop
if ( have_posts() ) :
while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
endwhile;
else:
get_template_part( 'content', 'none' );
endif;
wp_reset_query();
?>