Ajax category pagination problem

I want to make a pagination or load more button for my ajax category display.

Here is my attempt, I have no idea how it can work out…Any ideas? Thanks a lot.

            add_action( 'wp_ajax_nopriv_load-filter', 'prefix_load_cat_posts' ); 
   add_action( 'wp_ajax_load-filter', 'prefix_load_cat_posts' );



    function prefix_load_cat_posts () {
 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $temp = $DamonQuery;
        $DamonQuery= null;
$DamonQuery = new WP_Query();

$cat_id = $_POST[ 'cat' ];
     $args = array (
    'cat' => $cat_id,
    'posts_per_page' => 10,
 'orderby' => rand,
'post__not_in' => $do_not_duplicate,
                'paged' => $paged,
    'order' => 'DESC'

);



$total = 14;

   $thumbnailno = array();



for($x=0;$x<$total;$x++) {
$thumbnailno[$x] = "http://www.chandamon.com/home/wp-content/uploads/nothumb" . $x     .      ".png";
}

        $DamonQuery->query($args);

        $max_page = $DamonQuery->max_num_pages;


ob_start ();

if ( $DamonQuery->have_posts() ) {
while ( $DamonQuery->have_posts() ) {
    $DamonQuery->the_post();
    if ( has_post_thumbnail( $music->post->ID ) ) {
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID),      'large');

echo ‘ ID . ‘” title=”‘ . the_title_attribute(‘echo=0’) . ‘” >’;
echo get_the_post_thumbnail($post->ID, ‘array(255,255)’);
echo ”;
}
else {
echo ‘ ‘ . ”;
echo ”;

}

}

$big = 999999999; // need an unlikely integer


    echo paginate_links( array(

'format' => '#',
'current' => max( 1, get_query_var('paged') ),
    'total' => $DamonQuery->max_num_pages 
    ) );        

 wp_reset_postdata();


$DamonQuery= null;
 $DamonQuery= $temp;
}

 echo '</div>';






$response = ob_get_contents();
ob_end_clean();

echo $response;
die(1);
}

Read more here: Ajax category pagination problem

Leave a Reply

Your email address will not be published. Required fields are marked *