Skip Navigation

[Resolved] Have search filters find items not assigned to any filtered category

This support ticket is created 5 years, 7 months ago. 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.

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/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by johnB-43 5 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#1283985

I am trying to:
Set up a search with filters. I have a news site where various news items are either specific to a particular location or issue, or are general and apply to all. I would like the search filters on this page to reflect that.

Link to a page where the issue can be seen:
hidden link

I expected to see:
When I filter by, say, country, I would like the results to be:
- all of the items which have the selected country category assigned to them
- all of those that have a parent category to that selected assigned to them (in my case, continent)
- all those that don't have any country assigned (as those are general and apply to all countries)

For example, if on the linked page you choose 'Singapore' as the country, it will only display the 'Singapore News' post, but not the 'General News' post which has no country assigned at all, or 'Asia News' which has a parent country category assigned.

I realise that I can do that by simply selecting all the items from the 'country' taxonomy for posts which apply to all countries. But that means that all of those will get displayed in the loop creating a massive list in each general news item. Also, this is laborious, especially for this taxonomy, as it's likely there will be a lot of items under 'country' on my site.

Instead, I got:
Currently, the filter returns only the items which explicitly have the selected country assigned

#1284427

Hello,

There isn't such kind of built-in feature within Toolset Views plugin.

In your case, if you are familiar with PHP codes, you can consider custom codes, for example:

1) When user submit the search form, use filter hook wpv_filter_query to trigger a PHP functions
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

2) In this PHP function do these:
a) Get the country URL parameter:
hidden link
b) Get the parent term's value by above country URL parameter:
https://wordpress.stackexchange.com/questions/165270/get-parent-id-by-term-id
c) Add parent term's value into view's query
d) Add posts without term without any term assigned
https://wordpress.stackexchange.com/questions/159302/show-posts-without-term

More help:
https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

#1287609

Thanks! I'll look through this and try to come up with some solution.