0

In wordpress website i get 200 plus post with Ajax post filter.

This is the Ajax post filter code:

HTML:

<div class="filter-output"> Ajax Output   </div>

PHP:

 // The query (compiled)
$query = new WP_Query( array(
  'post_type'       => 'tablet',
  'meta_query'  => $meta_query
));

// The Loop
if( $query->have_posts() ) :
 while( $query->have_posts() ): $query->the_post();
    get_template_part('content');
endwhile;
   wp_reset_query();
else :
   _e('Sorry, no posts matched your criteria.');
   wp_send_json($query->posts);
endif;
   the_posts_pagination() ;
die(); 

Jquery:

jQuery(document).ready(function($){
  $('#test .br').click(function(){
  var choices = {};
  console.log(choices);

$.ajax({
    url: ajaxobject.ajaxurl,
    type :'POST',
    data : {
      'action' : 'call_post',
      'choices' : choices,
  },

success: function (result) {
    $('.filter-output').append(result);
  }     
 });
})
});

What is Solution for 200 plus post which get by Ajax? Pagination , Load more post button or else.

I post question here after waste a lot of time on work and Google search. But i have no solution.

Any help will be appreciated...

5
  • 1
    See this answer. You have to pass a page number or offset with your ajax call, and use that to query for a specific page of results.
    – Milo
    May 12, 2017 at 0:37
  • Thanks great tutorial. I have problem because something different here. In my situation i need offset for Ajax filter result not simple search result. So can you help me in question PHP part. How & what will be HTML part for loadmore button in my php
    – FRQ6692
    May 12, 2017 at 6:45
  • @Milo Here is the Link where i testing this
    – FRQ6692
    May 12, 2017 at 7:22
  • Same answer. You need to pass query arguments the same way you pass page number.
    – Milo
    May 16, 2017 at 14:57
  • @Milo can you please post answer here with changing pass query arguments. i am new with wordpress and also try many times but fail to achive it.
    – FRQ6692
    May 16, 2017 at 15:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.