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
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
Thanks! I'll look through this and try to come up with some solution.