add_action('wp_ajax_aquatics_filter_products', 'aquatics_filter_products'); add_action('wp_ajax_nopriv_aquatics_filter_products', 'aquatics_filter_products'); function aquatics_filter_products() { $state = isset($_POST['state']) ? json_decode(stripslashes($_POST['state']), true) : []; $default_category = sanitize_text_field($_POST['default_category'] ?? ''); $args = [ 'post_type' => 'product', 'posts_per_page' => 12, 'post_status' => 'publish' ]; // CATEGORY FILTER (Flexi Bar + Sidebar) if (!empty($state['categories'])) { $args['tax_query'][] = [ 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => $state['categories'] ]; } elseif (!empty($default_category)) { $args['tax_query'][] = [ 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => [$default_category] ]; } // SEARCH if (!empty($state['query'])) { $args['s'] = sanitize_text_field($state['query']); } // PRICE FILTER if (!empty($state['price']['min']) || !empty($state['price']['max'])) { $price_query = ['relation' => 'AND']; if (!empty($state['price']['min'])) { $price_query[] = [ 'key' => '_price', 'value' => floatval($state['price']['min']), 'compare' => '>=', 'type' => 'NUMERIC' ]; } if (!empty($state['price']['max'])) { $price_query[] = [ 'key' => '_price', 'value' => floatval($state['price']['max']), 'compare' => '<=', 'type' => 'NUMERIC' ]; } $args['meta_query'][] = $price_query; } $query = new WP_Query($args); if (!$query->have_posts()) { echo '