filter with url params

Hi
Is it possible to filter a dataset on a dynamic page with url params: mywixsite.com/services?category=cleaning&category=cooking

My idea is to show only content (services) that matches to user data from a previous questionary (typeform).

Thanks very much!

Hi,
there are two possible solutions:

  • Get query params using the Wix Location API . Then filter using the result.

  • Second option is to store users input in storage and on the relevant page get it from the storage and use to filter content. Click here to learn about Wix storage.

Hi Aleks
Thank you very much for your help!!

Is it also possible to filter by params with mutiple values? ?tags=one, two, three
I like to show the entries with the tags one, two and three (with one tag it works nice).

Thanks again!

Here is my code so far:

import wixLocation from ‘wix-location’;
import wixData from ‘wix-data’;
const collectionName = ‘Testservices’;
const fieldToFilterByInCollection = ‘tags’;
$w.onReady( function () {
const selectedTags = wixLocation.query[“tags”];
$w(‘#tags’).value = wixLocation.query[“tags”];
setRepeatedItemsInRepeater()
loadDataToRepeater(selectedTags)
});
function loadDataToRepeater(selectedCategories = []) {
let dataQuery = wixData.query(collectionName)
if (selectedCategories.length > 0) {
dataQuery = dataQuery.hasAll(fieldToFilterByInCollection, selectedCategories)
}

dataQuery
.find()
.then(results => {
const itemsReadyForRepeater = results.items
$w(‘#servicerepeater’).data = itemsReadyForRepeater;
const isRepeaterEmpty = itemsReadyForRepeater.length === 0
if (isRepeaterEmpty) {
$w(‘#noResultsFound’).show()
} else {
$w(‘#noResultsFound’).hide()
}
})
}
function setRepeatedItemsInRepeater() {
$w(‘#servicerepeater’).onItemReady(($item, itemData) => {
$item(‘#serviceimage’).src = itemData.serviceImage;
$item(‘#servicename’).text = itemData.serviceName
$item(‘#short’).text = itemData.serviceTagline;
$item(‘#preis’).text = itemData.priceSummary;
})
}