Filter Gallery Based on Tags

We are setting up a portfolio with projects that belong to one or more category which we’ve represented in our database as tags. We have a dropdown menu that contains all of the tags we’ve used and we’d like to filter the projects that appear based on the category (market) that is selected - just one category at a time.

I got fairly far using the code described in this tutorial
https://www.youtube.com/watch?v=Hx7_8-lRsW0&ab_channel=Wix.com

but I cannot figure out how to compare the dropdown selection with the the tag field (market) in the dataset to see if it contains the specific tag.

Can someone assist me with syntax for this? I’ve done quite a bit of searching but to no avail.

Thanks in advance.

// For full API documentation, including code examples, visit https://wix.to/94BuAAs
import wixData from 'wix-data'; 
$w.onReady(function () {
    wixData.query('Projects');

});

let lastFilterTitle;
let lastFilterMarket;
let debounceTimer;
export function iName_keyPress(event) {
 if (debounceTimer) {
        clearTimeout(debounceTimer);
        debounceTimer = undefined;
    }
    debounceTimer = setTimeout(()=> {
        filter($w('#iName').value, lastFilterMarket);

    }, 200);
//  console.log($w('#iName').value); 
    filter($w('#iName').value);
}

function filter(title, market) {
 if(lastFilterTitle !== title || lastFilterMarket !== market) {
 let newFilter = wixData.filter();
 if(title) 
            $w('#projectData').setFilter(wixData.filter().contains('title',title));
 if(market)
            $w('#projectData').setFilter(wixData.filter().contains('market',market));

        $w('#projectData').setFilter(newFilter);        
        lastFilterTitle = title; 
        lastFilterMarket = market;
    }
 
}

export function iMarket_change(event, $w) {
    filter(lastFilterTitle, $w('#iMarket').value);

}

I don’t get it either - the TAG fonction in the collection is useless if it can’t be use to filter… Actually the option “filter with the datas from user” in present for filtering a gallery wich content a collection but it’s unaccessible.

Have you seen this example? https://www.wix.com/corvid/example/filter-with-multiple-options
Hope it helps!

Hi Marlowe - I think the example you’ve sent is exactly what I want in terms of being able to filter an online shared family gallery - filtering photos based upon who’s in them, year, location etc. And combining these choices if wanted - e…g all pictures of James and Harold in Italy.

But so far, I haven’t coded at all in WIX - just been attempting to use the content management features and user input - and the above posts seem to confirm what I’ve found - that you cannot filter user input on tags. Tags only work when the filters are based on fixed settings for a particular page.

Is coding the only way to get this fuctionality? Or are WIX going to implement it any time soon?

Thanks.

Hi Marlowe. I have seen this example, but it refers to filtering Repeaters, not Gallery items. What do I have to change for it to filter a gallery of images by tags?

I need to do something exactly like this example: https://eyalcwix.wixsite.com/selectiontags-filter

@tantocontato I wondering the same!