Hello, I have a wix site which has the blog app and I want to filter all the blog/posts displayed in my site by a "single condition".
Imagine that I want to only display the POSTS where the title starts with "Shop."
If post title is " Shop this guitar" it will be displayed.
If post title is "Play guitar", it will not be displayed.
I'm a developer, but I'm struggling so much with corvid haha it seems that I do not know nothing.
In regular coding languages, I would just add a where condition to the database query on posts table.
In this case, I see that we can use Hooks "beforeQuery" or "beforeGet". Which I'm confused which one, but I'm trying with both just in case.
I added 2 hooks just to test the console.out("hooks being fired") but it seems not to work, in the following example nothing is shown in the developer console (F12 nor wix console).
![](https://static.wixstatic.com/media/a27d24_062e30e637204afeac2c2061519509dc~mv2.png/v1/fill/w_714,h_498,al_c,q_85,enc_auto/a27d24_062e30e637204afeac2c2061519509dc~mv2.png)
So my data.js is like this:
export function Blog$Posts_beforeGet(itemId, context) {
//TODO: write your code here...
console.log('Data hook fired');
}
export function Blog$Posts_afterGet(item, context) {
//TODO: write your code here...
console.log('Data hook fired');
return item;
}
So, my question is:
How can I filter by code the "original" query that wix makes to the blog/posts?.
Imagine that I just want to add a single "AND" condition to the query that wix does to the blog/posts.
Can I achieve it by using hooks? Which event?
P.D.: I know you can make a dynamic page with custom feed and load the blog posts, but, there the rich text is not displayed, so, I would like to use the Wix Blog App page but filtering the posts that are displayed by a "custom" query.
Thank you!
Hello GOS, thank you. I'm trying to pursue your option, which works with repeaters.
I'm, still wondering if I can change the "standard" query of the Blog/Posts collection and add some filters, that would fix my problem from the root.
Thank you for your help
There is nothing stopping you putting a dataset element on your page and simply connecting that to the Wix Blogs collection.
https://support.wix.com/en/corvid-by-wix/wix-blog-with-corvid
Also, look at this example here.
https://www.wix.com/corvid/example/filter-with-multiple-options
You can use this to work with the Wix Blog as shown in this previous post.
https://www.wix.com/corvid/forum/community-discussion/filtering-blog-posts-to-a-repeater-code-problem
Thank you for your help, but I believe datasets only works in dynamic pages, not in the "blog" wix page.
Here I can't see the "dataset" to apply the filter, because it's the "wix blog" element.
It seems to me that you only need a function to set the filter based on the customer input, have you considered setFilter in the dataset as the following :
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#setFilter
something like :
import wixData from 'wix-data';
function filter( name ) {
$w("#myDataset").setFilter( wixData.filter()
.startsWith("title", name)
)
.then( () => {
console.log("Dataset is now filtered");
} )
.catch( (err) => {
console.log(err);
} )
}