Based on this example , I am trying to use selection tags on a sample blog page so that users can narrow down blog posts to those that have more than one category in common. Right now, I’m trying to get the database query set up properly.
This is the code I’ve written:
import wixData from 'wix-data';
$w.onReady(function () {
$w('#tags').onChange((event) => {
const selectedTags = $w('#tags').value;
console.log(selectedTags);
loadDataToBlog(selectedTags);
})
});
async function loadDataToBlog(selectedCategories = []) {
let dataQuery = wixData.query("Blog/Posts");
if(selectedCategories.length > 0) {
dataQuery = dataQuery.hasAll('categories', selectedCategories);
}
let results = await dataQuery.find();
console.log(results);
}
Under my posts database, I have two posts saved within a “Shoutouts” category as listed in the category field for those ones:
So according to the code I’ve written, I’m expecting to see two items listed in the results variable, but that does not seem to be the case unfortunately
Any clue as to what I might have done incorrectly?
Also I used this link to try and resolve but it didn’t help: https://www.wix.com/corvid/forum/community-discussion/filtering-blog-posts-to-a-repeater-code-problem