I need a View that outputs a grid of posts, but filtered by chosen post categories.
I want this View to contain a search function with a drop-down list (or checkboxes) for those specific categories.
I have created the View using Toolset Blocks.
Under the "Content Selection" > Query Filter , I've applied a filter on the taxonomy to only show the categories I need.
But - when I add a Search for the categories (either a drop-down, or a check-box format) it loses the Query filter - the search displays all category names, and the View output loop shows posts from ALL categories.
It feels like I am missing something really obvious!
Hi,
Thank you for contacting us and I'd be happy to assist.
Your observation is correct and this is the expected behavior. If a static query filter for a taxonomy is added through "Content Selection > Query Filter", it will be overridden by the dynamic query applied by the front-end search field for that same taxonomy.
To achieve what you're planning, you'll need to take care of two things:
1. You can hide the unwanted category term options from the front-end filter using custom CSS code, so that the user can't select them.
( it would be simpler if you use the select/drop-down type filter )
2. To dynamically apply a static query filter for the selected categories, only when a user has not selected it from the front-end, you can remove it from "Content Selection > Query Filter" and instead apply it through the "wpv_filter_query" filter:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
You'll find a relevant usage example in this reply:
https://toolset.com/forums/topic/custom-taxonomy-dynamically-choose-all-filter/#post-1617211
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
Hi Waqar,
I had assumed that once I had set the Query filter to control the content of the View, the search drop-downs from the category would inherit those settings and only display the options specified in the filter.
(That would be a really useful option, no? )
I think I'll just scrap the idea of including the search and go for buttons hardcoded to category archives instead.
thanks
Thanks for writing back.
I've performed some further tests and can confirm that the static query filter is not added with the dynamic front-end search filters, but the dynamic one overrides the static one.
You're welcome to share this as a feature request at:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/
Meanwhile, using hardcodes category filter buttons sound like a good alternative.