Filtering a Filtered Search Result

So I have this page set-up where people can type in their town, city etc and filter the results of a big events list to find results in there city. That all works great.

https://www.virtueforanimals.org/getactive

People can submit events to the database and in the database itself we have an ‘approve’ field which we can tick to allow that event to show up once we have checked it over.

We have a filter set so it only shows events that have ‘approve’ ticked but are finding that when we search for something the search results ignore that filter and will show unapproved events.

What we need is a way to have all search results only show events that have ‘approve’ ticked.

This is the code I have for the search. Any help would be amazing.

Please note : I’m very new to wix coding so if you can keep the answer quite simple that would be great :slight_smile: Thank you x

import wixData from “wix-data”;

export function iTitle_keyPress(event, $w) {
filter($w(‘#iTitle’).value);
}

function filter(title) {
const filterValue = $w(“#iTitle”).value
const byTitle = wixData.filter().contains(“title”, filterValue)
const byCity = wixData.filter().contains(“city”, filterValue)
const byCounty = wixData.filter().contains(“countyState”, filterValue)
const byCountry = wixData.filter().contains(“country”, filterValue)
const byApprove = wixData.filter().contains(“approve”, filterValue)
$w(“#dataset1”).setFilter(byTitle.or(byCity).or(byCounty).or(byCountry))

}

Just bumping this as not heard from anyone. Hope that’s ok x

Bumping for one last try. Can anyone help?

hello Chris !

First of all you have to filter based on the fields after that you have to only show the approved ones, so you need another filter. it should look as follows.

$w("#dataset1").setFilter(byTitle.or(byCity).or(byCounty).or(byCountry)).then((res)=>{

        $w('#dataset1').setFilter(wixData.filter().eq("newField", true))
 
    })

however, maker sure of the fields keys when setting the filter ( the key for the field Approve not the name) so here the key is ‘newField’ not ‘approve’.

Best!
Massa