Question:
Where did I go wrong?
Product:
Editor
What are you trying to achieve:
I need to get BOTH filters applied in search results, and not “either or”
For example, in our website we have “Features & Amenities” filters
We have programmed a sample properties with: Golf only, Pool only, and both golf & pool
If I click search, it returns 5 results:
The two results with X marks should not go there because it only has “either” of the filter and not “both”
What have you already tried:
I tried this code… (fyi i have pagination code at the top too)
import wixData from ‘wix-data’;
import wixWindow from ‘wix-window’;
$w.onReady(async function () {
$w(‘#pagination1’).onClick(() => {
$w(‘#text11’).scrollTo();
});
try {
// Perform an initial query to fetch all items
const initialResults = await wixData.query('#dataset1').find(); // Assuming #dataset1 is the ID of your dataset
// Construct a new query based on the initial results
let filteredQuery = initialResults.query;
// Obtain selected filter values from the CheckboxGroup
const selectedFilters = $w('#checkboxGroup1').value; // Assuming checkboxGroup1 is the ID of your CheckboxGroup element
// Apply each selected filter value to the query as an AND condition
selectedFilters.forEach(filterValue => {
filteredQuery = filteredQuery.ge('F&A New', filterValue); // Replace 'F&A New' with the actual field name
});
// Perform the filtered query to retrieve matching results
const filteredResults = await filteredQuery.find();
// Display filtered results to the user (e.g., update a repeater or display data on a page)
// Example: $w('#repeater1').data = filteredResults;
} catch (error) {
console.error('Error fetching search results:', error);
}
});
THANK YOU!
Additional information:
NA