I wanna start by apologize for this post being so long, but I feel it may help others since I am having this problem and figured I might as well be as detailed as possible.
I am having a problem with this is the loop.php file loading the same post multiple times and I have tried the prevent duplicate post method and nothing working. As you can see below I am loading the function to post into the ajax function and I get a success call but at this point I am not sure if the loop file is the problem. When the site 1st loads it loads the 1st set of post and then when it gets the 2nd set of post its fine but everything after that is all the same post, its like the loop file loads but the query is stuck or something.
Any suggestions? Any help is greatly appreciated.
loop.php file
<div class="post-left">
<?php query_posts(array('post__not_in' => $id_merge,'posts_per_page'=>'2'));
$do_not_duplicate = $post->ID;
if (have_posts()) : while (have_posts()) : the_post();
if( $post->ID == $do_not_duplicate ) continue;
$ids[] = get_the_ID(); ?>
<div class="images-grid-page-wrapper">
<?php the_title(); ?>
</div>
<?php endwhile; endif; // End the loop. Whew. ?>
</div>
<div class="post-mid">
<?php query_posts(array('post__not_in' => $id_merge,'posts_per_page'=>'3'));
$do_not_duplicate = $post->ID;
if (have_posts()) : while (have_posts()) : the_post();
if( $post->ID == $do_not_duplicate ) continue;
$ids[] = get_the_ID(); ?>
<div class="images-grid-page-wrapper">
<?php the_title(); ?>
</div>
<?php endwhile; endif; // End the loop. Whew. ?>
</div>
functions.php
add_action('wp_ajax_infinite_scroll', 'wp_infinitepaginate'); // for logged in user
add_action('wp_ajax_nopriv_infinite_scroll', 'wp_infinitepaginate'); // if user not logged in
function wp_infinitepaginate(){
$loopFile = $_POST['loop_file'];
get_template_part( $loopFile );
exit;
}
ajax
jQuery(document).ready(function($) {
var count = 1;
var total = <?php echo $wp_query->max_num_pages; ?>;
$(window).scroll(function(){
if ($(window).scrollTop() == $(document).height() - $(window).height()){
if (count > total){
return false;
}else{
loadArticle(count);
}
count++;
}
});
function loadArticle(){
$('a#inifiniteLoader').show('fast');
$.ajax({
url: "<?php bloginfo('wpurl') ?>/wp-admin/admin-ajax.php",
type:'POST',
data: "action=infinite_scroll&loop_file=loop",
success: function(html){
$('a#inifiniteLoader').hide('1000');
$("#content").append(html); // This will be the div where our content will be loaded
}
});
return false;
}
});
