Skip Navigation

[Resolved] I want to add parent texonomy and child texonomy search filter dropdown in view

This support ticket is created 3 years, 10 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#1673203

I want to add parent texonomy and child texonomy search filter dropdown in view

#1673887

Hello, unfortunately the short answer is there is no simple way to achieve this in the current software. In a custom search View it is only possible to filter by the fields and taxonomies applied to the post type being queried. So if the custom post type selected in the Content Selection area is post type A, you can only add taxonomy filters for those taxonomies and terms applied to post type A. If a taxonomy is applied to a related post type B, it is not possible to filter by that taxonomy. You can also filter by post relationship, but not by the fields and taxonomies of that related post type. This is a limitation of the current software, and unfortunately there is not a simple workaround that requires no additional PHP or JavaScript knowledge.

With that being said, there are a few workarounds you may find useful:
- Workaround #1 -
Apply conditionals in the View's loop to exclude posts based whether or not the parent post has a specific term applied. This approach requires you to create a custom filter with HTML and conditional shortcodes to test for a specific term with the has_term function from WordPress. There are additional limitations, specifically related to pagination and number of results found. With a large number of results, this query could also be resource-intensive. For very simple cases with a limited number of results, it might be the most practical solution.

- Workaround #2 -
If you are a developer with advanced PHP and JavaScript abilities, you may be able to customize your View to accomplish something similar with our Views filters and PHP post relationships APIs. Unfortunately there is no JavaScript API available for Views filters, so the front-end filter interaction required for complex customized search filters is not supported here in the forums. It would be best to try to incorporate any custom filter without any AJAX interactions in the View. If you'd like more information about the PHP APIs for Views and post relationships, I will be glad to direct you to that documentation and provide any support you need for those components:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/
https://toolset.com/documentation/programmer-reference/views-filters/

- Workaround #3 -
Another possible workaround is to include the taxonomies for the parent post type in the queried post type. You could manually apply the same terms from the parent post type to the queried post type, or you could again use custom code to programmatically manage those terms whenever a parent post or child post is saved using the save_post hook. The PHP required to do this is relatively advanced as well, and uses the same APIs I mentioned before plus a few WordPress APIs like wp_get_object_terms and wp_set_object_terms:
https://developer.wordpress.org/reference/functions/wp_get_object_terms/
https://developer.wordpress.org/reference/functions/wp_set_object_terms/
https://developer.wordpress.org/reference/hooks/save_post/

Please let me know if you would like more information about exploring one of these custom approaches, and I can give you additional feedback.

#1683565

My issue is resolved now. Thank you!

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