So we have a dynamic employees page, and want to display blog posts by that specific user on each page. We have a category created for each user.
The issue is that we can’t use the GUI for the filters since the filter value is dynamically created.
Is there a way to run setFilter() on the data but pass in the reference data along with the dynamic value for the filter?
Similar to this question - but with a dynamic value - https://www.wix.com/corvid/forum/community-discussion/answered-dynamic-dataset-filter-reference-field
Note that it sounded like that forum user had added their own dataset to the Wix Editor and so would have more options available to them.
Whereas in your case, If you are using the Wix Blog, then note that it is still technically a Wix app, however you can do certain things with it through Corvid.
Here are the Corvid pages for the Wix Blog collections with details on how to query them. Just note that the code example at the top does not contain a query function as you have to add it and that some fields can only be filtered by a particular query etc.
https://support.wix.com/en/corvid-by-wix/wix-blog-with-corvid
Plus, if you go to the Examples section of this forum.
https://www.wix.com/corvid/examples
Then choose the Blog tab, you will be taken to the tutorials for the six custom things that you can do with the Wix Blog app.
Super helpful. Never found that page. So am i not able to do a lookup for blog posts, but then filter by a specific category? I see you can filter those options but when running the query i get an error for categories.
So it’s not possible to do something like this?
let name = data.name;
wixData.query("Blog/Posts")
.contains('categories', `News-${name}`)
.find()
.then( (results) => {
// handle the results
console.log(results)
} );
All i’m wanting to do is show posts with a certain dynamic category.
Hi Matt,
Did you figured out how to solve your problem?
@mattbtay
As noted in the Wix Blog Posts collection for Categories you can only use hasSome, hasAll and contains
https://support.wix.com/en/article/corvid-wix-blog-posts-collection-fields#categories-categories
However, please also note that the field type is Multiple-item reference and therefore you need to be looking for the ID in your contains query.
You can read more about it here.
https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html#contains
You can use contains() with a property whose value is a String or a Reference. For properties of type reference it is recommended that you use the eq() function instead of contains(). With properties that are References, contains() matches by the ID of the referenced item as a String.
You can find more about reference fields from previous posts in this forum like here.
https://www.wix.com/corvid/forum/community-discussion/wixdata-get-unable-to-use-results
Plus on Wix pages here.
https://support.wix.com/en/article/about-reference-fields-in-database-collections
https://support.wix.com/en/article/about-your-database-collection-fields#system-fields
https://www.wix.com/corvid/reference/wix-data.html#queryReferenced
https://www.wix.com/corvid/reference/wix-data.WixDataQueryReferencedResult.html
Finally, have a look at this Wix example for multiple references that you can open up in your own Wix Editor with all code setup etc.
https://www.wix.com/corvid/forum/community-discussion/example-wix-data-multiple-references
I filtered by related categories based on the currently displayed post both with data query (actually based on the related posts example) and with using a dataset and filters in functions, both options worked fine with Wix Blog.
like this:
function LoadRelatedCategoryPosts() {
return wixData.query(“Blog/Posts”)
.ne(“_id”, currentPost._id)
.hasSome(“categories”, currentPost.categories)
.find()
.then(results => {
$w(“#RelatedCategoryPostsRepeater”).data = results.items;
})
or this:
function filter() {
filter = wixData.filter()
.ne(“_id”, currentPost._id)
.hasSome(“categories”, currentPost.categories);
$w(“#postsdataset”).setFilter(filter);
}
You could perhaps use a similar approach, get and define the currentitem category from the employee page before filtering on it with .contains currentitem.category . I rarely work with dynamic pages but reading the Wix reference info on getCurrentItem it works pretty similar and it should be possible to then filter on it using a .contains filter.
I also managed to actually filter a repeater on the author field a while ago, but then it stopped working. It is not mentioned in the Wix Blog “Posts” Collection Fields, so that probably was a bug.