Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

Ajax load more and voting

$
0
0

Replies: 0

Hi.
We replaced pagination to load more with ajax. But at the same time voting don’t work http://joxi.ru/Grq1BdOH4K6z0r
How is it possible to do?
ivole-single-product-reviews.php:

<?php
	$cpage = get_comment_pages_count();
            if ( $cpage > 1 && get_option( 'page_comments' ) ) {
            	echo '<div class="btn-more loadmore">Load more</div>
            	<script>
            	var ajaxurl = \'' . site_url('wp-admin/admin-ajax.php') . '\',
            	    parent_post_id = ' . get_the_ID() . ',
                	    cpage = ' . $cpage . '
            	</script>';
            }
	?>
		<script>
		jQuery(function($){
            	$('.loadmore').click( function(){
            		var button = $(this);
            		cpage--;            
            		$.ajax({
            			url : ajaxurl,
            			data : {
            				'action': 'cloadmore',
            				'post_id': parent_post_id,
            				'cpage' : cpage,
            			},
            			type : 'POST',
            			beforeSend : function ( xhr ) {
            				button.text('Loading...');
            			},
            			success : function( data ){
            				if( data ) {
            					$('ol.commentlist').append( data );
            					button.text('Load more'); 
            					if ( cpage == 1 )
            						button.remove();
            				} else {
            					button.remove();
            				}
            			}
            		});
            		return false;
            	});
             
            });
	</script>

functions.php:

add_action('wp_ajax_cloadmore', 'comments_loadmore_handler');
add_action('wp_ajax_nopriv_cloadmore', 'comments_loadmore_handler');

function comments_loadmore_handler(){
	global $post;
	$post = get_post( $_POST['post_id'] );
	setup_postdata( $post );
	wp_list_comments( apply_filters( 'woocommerce_product_review_list_args', array( 'callback' => 'woocommerce_comments', 'page' => $_POST['cpage'], 'per_page' => get_option('comments_per_page') ) ) );
	die;
}

Viewing all articles
Browse latest Browse all 59525

Trending Articles