Ajax filtering with Loop Grid
-
Hey,
I am working on creating custom AJAX posts filtering of default and custom created taxonomies. The issue with the Loop Grid widget is that whenever I use any type of pagination(I’ve also tried selecting the AJAX option), however when new sets of posts load it seems that the filtering logic isn’t being followed. I tried using SESSIONS/ WP transients with no luck. Possibly I am in the wrong somewhere, any chance on providing some hints as to what could be the issue?
This is part of the filter_posts() method.$_SESSION['filter_params'] = [ 'category' => $category, 'statuses' => $statuses, 'stores' => $stores, 'discounts' => $discounts, ]; $query = new WP_Query($args); ob_start(); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); echo do_shortcode('[elementor-template id="56168" query_id="my-custom-query"]'); } } else { echo do_shortcode('[elementor-template id="56168" query_id="my-custom-query"]'); } $content = ob_get_clean(); wp_reset_postdata(); wp_send_json_success($content); die();
Part of the custom query:
add_action('elementor/query/my-custom-query', function($query) { if (isset($_SESSION['filter_params'])) { $filter_params = $_SESSION['filter_params']; $categories = $filter_params['category'] ?? ''; $statuses = $filter_params['statuses'] ?? []; $stores = $filter_params['stores'] ?? []; $discounts = $filter_params['discounts'] ?? []; $tax_query = ['relation' => 'AND']; if (!empty($categories)) { $categories_terms = []; foreach($categories as $category) { $categories_terms[] = $category; } $tax_query[] = [ 'taxonomy' => 'product_categories', 'field' => 'slug', 'terms' => $categories_terms, ]; } if (!empty($tax_query)) { $query->set('tax_query', $tax_query); } } });
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- You must be logged in to reply to this topic.