load more button duplicates previous products

Question

Here is my handler to ajax request. What is my problem?

function loadmore_ajax_handler(){
        $args = [];
        $args['paged'] = $_POST['page'];
        $args['posts_per_page'] = 3;
        $args['post_type'] = 'product';
        query_posts($args);
        $response = [];

        while( have_posts() ): the_post();
            $product = wc_get_product(get_the_ID());

            $response[] = '
                <div class="catalog-goods-wrapper--card">
                    <img src="' . get_the_post_thumbnail_url() .'" alt="shoes" class="catalog-goods--good-preview" />
                    <div class="catalog-goods-wrapper--overlay"></div> 
                </div>
                <p class="catalog-goods--description">' . get_the_title() . '</p>
                <span class="catalog-goods--price">' . $product->get_price_html() . '</span>
                <i class="view-good"></i>';
                
            

        endwhile;
        wp_reset_query();

        echo json_encode($response);
        
        die; 
    }
0
user3598759 6 months 2022-06-12T12:00:23-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse