How to filter dataset by dropdown and user

I have a dataset that I have filtered by the current user (based on currentUser.getEmail) when it loads, so that users can see what’s in their account. I wanted to add a dropdown and a search bar so that they could further refine the content, and have followed the tutorials posted. The basic functionality works, however the dropdown/search bar filters run against the entire dataset, instead of the dataset filtered by the current user, so they no longer see just their items. I have tried to add a similar userEmail filter, but it doesn’t seem to be working. Any help would be greatly appreciated! Code below.

Note: I need to filter by current user and not owner because I am the one uploading the content into their accounts

import wixUsers from ‘wix-users’ ;
import wixData from ‘wix-data’ ;

$w.onReady( async function () {
let userEmail = await wixUsers.currentUser.getEmail()
$w( “#memberVc” ).onReady(() => {
$w( “#memberVc” ).setFilter(wixData.filter().eq( “userEmail” , userEmail))
});
});

$w.onReady(() => {
loadAgeRecommendation();
});

let lastFilterFood;
let lastFilterRecommendation;
let debounceTimer

export function iFood_keyPress(event,$w) {
if (debounceTimer){
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w( ‘#iFood’ ).value, lastFilterRecommendation);
}, 200 );
}

export function iRecommendation_change(event,$w) {
filter(lastFilterFood,$w( ‘#iRecommendation’ ).value);
}

function filter(food,ageRecommendation){
if (lastFilterFood !== food || lastFilterRecommendation !== ageRecommendation) {
let newFilter = wixData.filter();
if (food)
newFilter = newFilter.contains( ‘foodName’ ,food);
if (ageRecommendation)
newFilter = newFilter.contains( ‘ageRecommendation’ ,ageRecommendation);
let userEmail = wixUsers.currentUser.getEmail()
let emailFilter = wixData.filter().eq( ‘userEmail’ ,userEmail);
$w( ‘#memberVc’ ).setFilter(newFilter,emailFilter);
lastFilterFood = food;
lastFilterRecommendation = ageRecommendation;
}
}

function loadAgeRecommendation() {
wixData.query( “MemberVC” )
.limit( 10 )
.ascending( “ageRecommendation” )
.distinct( “ageRecommendation” )
.then(results => {
let distinctList = buildOptions(results.items);
distinctList.unshift({ “value” : ‘’ , “label” : ‘All Recommendations’ });
$w( “#iRecommendation” ).options = distinctList;
});
}

function buildOptions(items) {
return items.map(curr => {
return { label: curr, value: curr };
});
}

Hi,
what you currently do is override one filter with another.

What you need to do is combine all the filter parameters under one action (e.g. add a “filter” button click event that will gather user email, dropdown value and input element value and filter the dataset with this data).

And keep the filter only by the email for the page load.

You can see a similar example (but for the logged in user) here .

Thanks for the response! The example helped me understand my code in more detail and I was able to get it working.