• 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)
  • John Doe

    (@heartbreakkid58)

    @borkk85 are you able to solve this above mentioned functionality?
    I have a similar thing, where I’m showing custom posts in a Loop Carousel, and want to filter them via Taxonomy. There’s a widget “Taxonomy Filter” which do exactly the same thing which I want, but unfortunately it works ONLY with the Loop Grid, and I’ve a Loop Carousel.

    So, I want something like, to display a list of taxonomies through Shortcode, and on selection of the taxonomy (from the list), it changes the result from the ELementor Custom Query Filter.

    $meta_query[] = [
    'taxonomy' => 'service-cat',
    'field' => 'slug',
    'terms' => $term,
    ];

    $query->set( 'tax_query', $meta_query );

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.