# Filter results by reference field (.contains)

**URL:** <https://forum.wixstudio.com/t/filter-results-by-reference-field-contains/41422>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [April 2, 2018, 9:19am UTC](https://forum.wixstudio.com/t/filter-results-by-reference-field-contains/41422 "2018-04-02T09:19:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tristan-breon](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/tristan-breon/32/1231_2.png) [@tristan-breon](https://forum.wixstudio.com/u/tristan-breon)\
**Post date:** [April 2, 2018, 9:19am UTC](https://forum.wixstudio.com/t/filter-results-by-reference-field-contains/41422/1 "2018-04-02T09:19:00Z")

</div>

Hi !

I need help, I have a page that displays only certain items that contain the word “soldes” in the “evenement” field in the data collection, it worked well before, but I decided to set the “evenement” field as a reference, and now my code no longer works ! (no items are displayed on that page.

Here is a sample of the code :

```javascript
//filters available/not available items
export function checkbox1_change(event, $w) {
	$w('#loader').show();
	let filter = wixData.filter();
	if ($w("#checkbox1").checked)
 	{
    	filter=filter.ne("dispo", true);
	}
	filter = filter
		.contains("title", $w("#searchInput").value)
		.contains("categorie", $w("#categorieInput").value)
		.contains("vendeur", $w("#vendeurInput").value)
		.contains("type", $w("#typeRadio").value)
		.contains("evenement", "soldes");
	$w("#dynamicDataset").setFilter(filter)
	//hides loading screen after data was retrieved
	 .then( () => {       
            $w('#loader').hide();
     });
}

```

any help as to what to do so the page only displays according to the reference field ?

---

<div class="post-metadata">

**Author:** ![tristan-breon](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/tristan-breon/32/1231_2.png) [@tristan-breon](https://forum.wixstudio.com/u/tristan-breon)\
**Post date:** [April 2, 2018, 9:34am UTC](https://forum.wixstudio.com/t/filter-results-by-reference-field-contains/41422/2 "2018-04-02T09:34:16Z")

</div>

I’ve found this but it doesn’t work :

> **[\[Answered\] Dynamic dataset -\> filter reference field | Velo by Wix](https://community.wix.com/velo/forum/coding-with-velo/answered-dynamic-dataset-filter-reference-field)**
>
> Hi all. First post. Started Wix today for my own site. In future I'll need to make some addons, but I find most stuff is available, and that brings me to my first question, unknownity.
> 
> I see if I add a 'dataset' to a page, I can add filters to all...

---

<div class="post-metadata">

**Author:** ![giedrius-grazevicius](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/giedrius-grazevicius/32/711_2.png) [@giedrius-grazevicius](https://forum.wixstudio.com/u/giedrius-grazevicius)\
**Post date:** [April 3, 2018, 12:00pm UTC](https://forum.wixstudio.com/t/filter-results-by-reference-field-contains/41422/3 "2018-04-03T12:00:28Z")

</div>

Hi,

do you see those referenced fields displayed in the collection (that is values are blue as opposed to red)?

---

<div class="post-metadata">

**Author:** ![tristan-breon](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/tristan-breon/32/1231_2.png) [@tristan-breon](https://forum.wixstudio.com/u/tristan-breon)\
**Post date:** [April 3, 2018, 12:04pm UTC](https://forum.wixstudio.com/t/filter-results-by-reference-field-contains/41422/4 "2018-04-03T12:04:47Z")

</div>

Hi,

I’ve found a compromise, i added each page the ID of the referenced field to the filter.

---

<div class="post-metadata">

**Author:** ![shaunklomp](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/shaunklomp/32/3832_2.png) [@shaunklomp](https://forum.wixstudio.com/u/shaunklomp)\
**Post date:** [May 15, 2018, 5:49pm UTC](https://forum.wixstudio.com/t/filter-results-by-reference-field-contains/41422/5 "2018-05-15T17:49:12Z")

</div>

Can you show me your final code? I’m trying to filter by the reference field, but I guess wixcode won’t allow that?

---

<div class="post-metadata">

**Author:** ![tristan-breon](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/tristan-breon/32/1231_2.png) [@tristan-breon](https://forum.wixstudio.com/u/tristan-breon)\
**Post date:** [May 15, 2018, 5:55pm UTC](https://forum.wixstudio.com/t/filter-results-by-reference-field-contains/41422/6 "2018-05-15T17:55:07Z")

</div>

Hi,

What I did was create a reference field in the collection. Each reference field has a unique ID, and you can see that ID when you change your reference field to a plain text field (it will break connections and will show an error but it will display that unique ID).

Copy that ID and paste it to the code with the .contains feature :

```javascript
//searches keywords typed upon pressing 'Enter'
export function searchInput_keyPress(event, $w) {
	if (event.key === "Enter") {
	//shows a pre loader
		$w('#loader').show();
	let filter = wixData.filter();
	if ($w("#checkbox1").checked)
 	{
    	filter=filter.ne("dispo", true);
	}
	filter = filter
	//here is the ID linked to a reference in the collection
		.contains("evenement", "810fcbd1-becf-4471-8938-4a0c1afd38a0")
		//other criteria searched...
		.contains("title", $w("#searchInput").value)
		.contains("categorie", $w("#categorieInput").value)
		.contains("vendeur", $w("#vendeurInput").value)
		.contains("type", $w("#typeRadio").value);
	$w("#dynamicDataset").setFilter(filter)
	//hides loading screen after data was retrieved
	 .then( () => {       
            $w('#loader').hide();
            wixData.query("commentaires")
	  			.contains("reference", $w('#referenceText').text)
	  			.find()
		  			.then( (results) => {
						let numberOfItems = results.totalCount;
						$w('#nbrComments').text = numberOfItems + '';
					});
     });
	}
}

```
