Hi guys,
Hope you’re all well.
We have a News and Blog page on our website and would like to add a filter feature, similar to the example shared in the private content section. At the moment, we’re using the “Blog Posts” element, but I can’t find a way to create a filter that lets users select and view either News or Blog articles specifically.
Is this something that can be done with the current setup? If so, could you advise on how to achieve it?
It would also be great to add a label such as “News” or “Blog” to each post in the grid, like in the example link, if that’s possible too.
Would really appreciate your guidance on this.
Thanks,
Matt
Hey GoodfishGroup_Marketing,
Thank you for the inquiry.
You can add this code in the functions.php file to adjust the post grid query based on the value of cat query parameter.
function avia_post_grid_query_mod($query, $params) {
if ( isset($_GET['cat']) ) {
$category_id = intval($_GET['cat']);
if ($category_id) {
$query['category__in'] = array($category_id);
}
}
return $query;
}
add_filter('avia_post_grid_query', 'avia_post_grid_query_mod', 10, 2);
You may need to build the sorting buttons manually using the available elements in the builder.
Best regards,
Ismael