Skip Navigation

[Résolu] Create a Searchable View, filtered to only contain posts in specific categories

This support ticket is created Il y a 2 années et 9 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 3 réponses, has 2 voix.

Last updated by Waqar Il y a 2 années et 9 mois.

Assisted by: Waqar.

Auteur
Publications
#2101385

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!

#2101915

Waqar
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

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

#2102471

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

#2103635

Waqar
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

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.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.