Q: wp AJAX load more plugin repeating the same previous posts I using wp ajax load more plugin While clicking the button it repeating the same previous post. How to fix it. Here I share my code in below:
<?php
       $the_query = new WP_Query( array(
       'posts_per_page'=>10,//on loading page i show 10 after click load more i want to show other posts
       'post_type'=>'post-name',
       'category_name' => 'A-E',
       'orderby'=> 'title',
       'order'   => 'ASC',
       'paged' => get_query_var('paged') ? get_query_var('paged') : 1) 
      ); 
?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>

// here I print the following data

 <?php
      endwhile;
 ?>

 <?php
      echo do_shortcode('[ajax_load_more post_type="post-name" posts_per_page="10" category="a-e" button_label="Load More"]');
  ?>

can anyone fix it?

A: I just use this to solve my own problem:
 while ( $query->have_posts() ) : $query->the_post();

 $do_not_duplicate[] = $post->ID; // Store post ID in array
  // Other loop actions could go here

 endwhile; wp_reset_query();  

 $post__not_in = ($do_not_duplicate) ? implode(',', $do_not_duplicate) : '';     
 echo do_shortcode('[ajax_load_more post__not_in="'. $post__not_in .'" post_type="post-name" posts_per_page="10" category="a-e" button_label="Load More"]');


A: You don't need to create a custom query. You are using a plugin that will generate it for you via their shortcode. As per their documentation, you can just create your settings for the shortcode.
See instructions here https://connekthq.com/plugins/ajax-load-more/docs/shortcode-builder/
Just take the generated shortcode and paste it into your page/post or in your php file with do_shortcode.
The plugin handles the query and the posts per page etc.

A: If you want to get the next set of pages with ajax-load-more you must use the offset parameter. The ajax-load-more plugin must get the next posts that WP_Query has. So both WP_Query and ajax-load-more must query the same pages. First alter the shortcode to be same as WP_Query, by adding order and orderby parameter:
[ajax_load_more post_type="post-name" posts_per_page="10" order="ASC" orderby="title" category="a-e" button_label="Load More"]

Then add offset=(get_query_var('paged') ? get_query_var('paged') : 1)*10 like this:
[ajax_load_more post_type="post-name" offset='.((get_query_var('paged') ? get_query_var('paged') : 1)*10).' posts_per_page="10" order="ASC" orderby="title"  category="a-e" button_label="Load More"]

Note: Seems like ajax-load-more doesn't know of - so you must separate category or post_type by ,. Unless you have actually a category named a-e
