• // ajax code for request test ride details
    add_action( 'wp_ajax_nopriv_request_by_filter', 'request_by_filter' );
    add_action( 'wp_ajax_request_by_filter', 'request_by_filter' );
    function request_by_filter()
    {
    	$typecatArr = $_POST['typearr'];
    	//print_r($typecatArr);
        $type_arr = explode (",", $typecatArr); 
    	
        $finishcatArr = $_POST['finisharr'];
    	//print_r($finishcatArr);
        $finish_arr = explode (",", $finishcatArr);
    
        $sizecatArr = $_POST['sizearr'];
    	//print_r($sizecatArr);
        $size_arr = explode (",", $sizecatArr);
    
        $post_type = $_POST['post_type'];
        $type = $_POST['type'];
        $finish = $_POST['finish'];
        $size = $_POST['size'];
        
        $paged = get_query_var('paged') ? get_query_var('paged') : 1;
        $args = array(
            'post_type' => $post_type,
            'posts_per_page'=> 12,
            'paged' => $paged,
            'post_status' =>'publish',
            'orderby' => 'menu_order',
            'order' => 'DESC'        
        );
        if($type_arr || $finish_arr || $size_arr)
        {
            $tax_query['tax_query'] = array( 'relation'=>'AND' );
        }
        $args = array_merge_recursive( $args, $tax_query);
        if(!empty($typecatArr))
        {
            $tax_query['tax_query'] = array(
    			array(
    				'taxonomy' => $type,
    				'field' => 'term_id',
    				'terms' => $type_arr,
    			)
    		);
            $args = array_merge_recursive( $args, $tax_query);
    
           // print_r($args);
        }
        if(!empty($finishcatArr))
        {
            $tax_query['tax_query'] = array(
    			array(
    				'taxonomy' => $finish,
    				'field' => 'term_id',
    				'terms' => $finish_arr,
    			)
    		);
            $args = array_merge_recursive( $args, $tax_query);
           // print_r($args);
        }
        if(!empty($sizecatArr))
        {
            $tax_query['tax_query'] = array(
    			array(
    				'taxonomy' => $size,
    				'field' => 'term_id',
    				'terms' => $size_arr,
    			)
    		);
            $args = array_merge_recursive( $args, $tax_query);
        }
        
        $query = new WP_Query($args);
        if ( $query->have_posts() ) {
        ?>
            <div class="ajaxloader col-lg-10 col-md-9" id="ajaxloaderdiv" style="display:none;">  
                <img class="loading-image" src="<?php echo get_stylesheet_directory_uri(); ?>/framework/loader.gif" />
            </div>
            <div class="products-zindex">
                <div class="row">
                    <?php
                        while ( $query->have_posts() ) {
                            $query->the_post();
                            $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full');
                            $procatArr = wp_get_post_terms( get_the_ID(), $finish ); 
                    ?>
                        <div class="col-sm-3 col-md-6 col-lg-4 col-xl-2 ajaxscrollload">
                            <div class="zindex-product-detail">
                                <a href="<?php echo get_permalink(); ?>">
                                    <div class="product-img">
                                        <img src="<?php echo $featured_img_url; ?>" alt="<?php the_title(); ?>" class="img-fluid">
                                    </div>
                                    <div class="product-data">
                                        <h5><?php the_title(); ?></h5>
                                        <h6> 
                                            <?php
                                                $comma_string = array();
                                                foreach( $procatArr as $catval ) {            
                                                    $comma_string[] = $catval->name;         
                                                }
                                                echo $productname = implode(", ", $comma_string);
                                            ?>
                                        </h6>
                                    </div>
                                </a>
                            </div>
                        </div>
                    <?php } 
                        echo "<nav class=\"ajaxsw-pagination\">";
                        $big = 999999999; // need an unlikely integer
                        echo paginate_links( array(
                            'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
                            'format' => '?paged=%#%',
                            'current' => max( 1, get_query_var('paged') ),
                            'total' => $the_query->max_num_pages
                        ) );
                        echo "</nav>";
                        wp_reset_query();
                    ?>
                </div>
            </div>
        <?php } else { ?>
            <h2>No Product Found.</h2>
        <?php
        }
    
    	wp_die();
    	//exit;
    }
Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter zindexdecoders

    (@zindexdecoders)

    How to set infinite scroll in ajax. Can you help me?

    Plugin Support Leanza Francesco

    (@leanzafrancesco)

    Hi,
    and thank you for writing in!

    We’re afraid we didn’t understand well your point.
    Please could you provide us with further information about the goal you want to achieve?

    Thread Starter zindexdecoders

    (@zindexdecoders)

    Hello @leanzafrancesco,

    I have attached my wordpress PHP template page ajax response code…but ajax response code in not working pagination and infinite scroll.

    How to set infinite scroll in ajax. Can you help me?

    Thank You.

    Plugin Support Leanza Francesco

    (@leanzafrancesco)

    Hi,
    if you are loading your contents through AJAX, you should re-initialize the infinite scrolling.
    So, after loading the contents you could use a code snippet like the following one:

    $( yith_infs.contentSelector ).yit_infinitescroll( 
        {
            nextSelector    : yith_infs.nextSelector,
            navSelector     : yith_infs.navSelector,
            itemSelector    : yith_infs.itemSelector,
            contentSelector : yith_infs.contentSelector,
            loader          : '<img src="' + yith_infs.loader + '">',
            is_shop         : yith_infs.shop
        }
     );

    Please note: that code snippet will work fine only if the selectors are correctly set in the plugin settings and if the “next” pagination link is correct.

    Thread Starter zindexdecoders

    (@zindexdecoders)

    Hello @leanzafrancesco,

    Thank you for helping.

    But above my ajax response code in which place in put your code?

    Thank you.

    Plugin Support Alessio Torrisi

    (@alessio91)

    Hi there,
    I can’t say you exactly where place the code, but for sure you have to trigger that once the ajax event is fired.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Taxonomy Filter with Ajax in not working infinite scroll’ is closed to new replies.