Pagination in custom Filter
-
Hi,
I created a ajax filter which filters through meta-data using elastic search. I have made things running. Result is relevant but now the problem is pagination. I have used woodmart theme on my site and it has is on way to paginate.
Now my question is ‘Is there any in which I can have result paginated in the way theme was paginating by default.’
Filter is on the sidebar for product archive page of product. For result I was replacing the current content with filter result.
Here is jquery function to sending ajax request
function check(){ jQuery('body').addClass('ajaxLoading'); var value = {}; var tax_query = []; jQuery('input.term-check:checked').each(function(){ tax_query.push($(this).val()); }); jQuery.ajax({ url: "<?php echo admin_url('admin-ajax.php');?>", type: "POST", //url: epas.endpointUrl + JSON.stringify(data), //contentType: 'application/json', data: { action: 'search_post_data', //value : value, term: tax_query }, //data:JSON.stringify(data), success: function(response){ jQuery('div.woocommerce > div.products').children().remove(); jQuery( 'div.woocommerce > div.products' ).append( response[0] ); jQuery('body').removeClass('ajaxLoading'); } }) }
and This php function which getting response
function custom_ep_get_data(){ global $wpdb; $meta_query = array(); $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $tax_query = array(); if(isset($_POST['term'])){ $tax_query[] = array( 'taxonomy' => 'pa_certifications', 'field' => 'term_id', 'terms' => $_POST['term'], ); } $args = array( 'post_type' => 'product', 'tax_query' => $tax_query, 'posts_per_page' => 12, 'pagination' => true, 'ep_integrate' => true, ); $wc_query = new WP_Query($args); if( $wc_query->have_posts() ){ // Start "saving" results' HTML $results_html = ''; ob_start(); while( $wc_query->have_posts() ) { $wc_query->the_post(); echo wc_get_template_part( 'content', 'product' ); } wp_reset_postdata(); // "Save" results' HTML as variable $results_html = ob_get_clean(); } else { // Start "saving" results' HTML $results_html = ''; ob_start(); echo '<div style="text-align:center"><h3>Not result found</h3></div>'; // "Save" results' HTML as variable $results_html = ob_get_clean(); } // Build ajax response $response = array(); // 1. value is HTML of new posts and 2. is total count of posts array_push ( $response, $results_html ); echo json_encode( $response ); echo json_encode( $wc_query ); wp_die(); }
I hope my query is clear.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Pagination in custom Filter’ is closed to new replies.