Hi there
I Followed this example that lets you filler by selection tags
https://www.wix.com/corvid/example/filter-with-multiple-options
It works fine, I managed to get it to work the blog collection on the site but I would like the collection that selection tag queries to be filtered by the relative blog category. In this case “O -Fitness”.
So I’ve tried this
const collectionName = wixData.query( “Blog/Post” ).contains( “categories” , [ “O -Fitness” ]);
Full code below.
import wixData from ‘wix-data’ ;
//const collectionName = ‘Blog/Posts’
const collectionName = wixData.query( “Blog/Post” ).contains( “categories” , [ “O -Fitness” ]);
const fieldToFilterByInCollection = ‘hashtags’ ;
$w.onReady( function () {
setRepeatedItemsInRepeater()
loadDataToRepeater()
$w( '#tags' ).onChange((event) => {
const selectedTags = $w( ‘#tags’ ).value
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( ‘#Stories’ ).data = itemsReadyForRepeater;
const isRepeaterEmpty = itemsReadyForRepeater.length === 0
if (isRepeaterEmpty) {
$w( ‘#noResultsFound’ ).show()
} else {
$w( ‘#noResultsFound’ ).hide()
}
})
}
function setRepeatedItemsInRepeater() {
$w( ‘#Stories’ ).onItemReady(($item, itemData) => {
$item( '#image' ).src = itemData.coverImage;
$item( '#title' ).text = itemData.title;
if ($item( “#title” ).text.length > 40 ){
$item( “#title” ).text =$item( “#title” ).text.slice( 0 , 40 ) + ‘…’ ;}
$item( ‘#excerpt’ ).text = itemData.excerpt;
if ($item( ‘#excerpt’ ).text.length > 100 ){
$item( ‘#excerpt’ ).text =$item( ‘#excerpt’ ).text.slice( 0 , 100 ) + ‘…’ ;}