Filter collection by multiple fields?

I have filtering set up on a repeater of a collection as follows:

export function TitleSearchButton_click(event, $w) {
//Add your code for this event here:

	.contains("title", $w("#filterInput").value) 


It works fine but I want it to apply #filterInput to not only “title” but also other fields. When I try to add another field like this:

.contains(“title”, $w(“#filterInput”).value)
.contains(“field2”, $w(“#filterInput”).value)

setFilter applies an AND where I want OR.

Any advice is appreciated.


Hi Rodd,

WixDataFilter has a handy method .or() which can help you in this case. You can combine two conditions like this:

const filterValue = $w("#filterInput").value
const byTitle = wixData.filter().contains("title", filterValue)
const byField2 = wixData.filter().contains("field2", filterValue)

Hi Egidijus, thanks for the response… it worked perfectly!

can you filter a dropdown menu options based on a selection form another dropdown menu?

Hi Brandon,

with Wix Code, everything is possible!

It seems to me that your question is unrelated to the original post. In order to keep the forum organized and easy to navigate for those who look for answers using search, why don’t you open a new topic for your question? Also, please share a bit more details on how you populate your dropdown menus with options. Thanks!

Yes Sir

can someone help me with a good explanation and pictures?

Check out this site

1 Like

You can share the code you use for your example?

I am trying to use a similar process in a new context and having a problem. Here is the code I am using:

export function TitleSearchButton_click(event, $w) {
const MINEonly = wixData.filter().contains(“authors”, “Smith”)
const filterValue = $w(“#filterInput”).value
const byREF = wixData.filter().contains(“full_ref”, filterValue) || $w(“#publicationsdataset”).setFilter(MINEonly)

So I have here a collection of publications, with citation data in the “full_ref” field. I also have an “authors” field that has only the name of the authors. The user can use the input box to add part of a name of a title of a paper, and then i want to filter by that… works fine. But I add another filter that only entries with “Smith” as an author would be filtered (MINEonly)…

When I run the script, the title filter works fine, but authors that don’t include “Smith” also come up. Please advise.

Hi Rodd,

the OR condition for WixData filter should be expressed as:

const MINEonly = wixData.filter().contains("authors", "Smith") 
const byFullRef = wixData.filter("full_ref", filterValue)
const byRefOrMine = byFullRef.or(MINEOnly)

@egidijus-jucevicius -thanks! Plus I need the AND condition, so I will change that :slight_smile: