Hey guys, I can’t get this to work and I need some help.
I am using Wix Editor and I have used CMS to create a collection for patterns/items. There are different categories within the page that are inside one collection called “all products” which are filtered by tags. I’d like for people to click on the link in the nav and lead them to this shop page and have it be filtered by wallpaper or fabrics, etc.
I’ve been trying to externally link directly to ‘shop > wallpaper’ but I can’t figure out what the best way to do this is.
I feel like I’m almost there because I’m able to link to the page but the filtered tag “wallpaper” isn’t working.
Thanks in advance!
Website URL for reference:
https://hello5198424.wixstudio.com/mairin-kareli-design
import wixLocationFrontend from 'wix-location-frontend';
import wixData from 'wix-data';
var selected = [];
var lastSelected = [];
var opts = [];
var query = wixLocationFrontend.query;
$w.onReady(async () => {
await $w('#dynamicDataset').onReadyAsync();
opts = $w("#selectionTags1").options;
if (query.filter) {
let filter = query.filter;
var index = opts.findIndex(function (element) {
return element.label === filter;
});
if (index == -1) {
filter = "All";
await $w("#dynamicDataset").setFilter(wixData.filter()
.hasSome("tagsTags", [filter])
);
} else {
lastSelected.push(index);
selected = lastSelected;
$w("#selectionTags1").selectedIndices = selected;
await $w("#dynamicDataset").setFilter(wixData.filter()
.hasSome("tagsTags", [filter])
);
}
}
$w('#selectionTags1').onChange((event) => {
if (selected.length == 0) {
selected = $w("#selectionTags1").selectedIndices;
} else {
lastSelected = $w("#selectionTags1").selectedIndices;
lastSelected = lastSelected.filter(item => !selected.includes(item));
selected = lastSelected;
$w("#selectionTags1").selectedIndices = selected;
wixLocationFrontend.queryParams.remove(["filter"]);
wixLocationFrontend.queryParams.add({ "filter": [opts[selected[0]].label] });
}
$w("#dynamicDataset").setFilter(wixData.filter()
.hasSome("tagsTags", [opts[selected[0]].label])
);
});
});