Skip Navigation

[Resolved] filter my taxonomy query before displaying my custom search

This support ticket is created 4 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 16 replies, has 2 voices.

Last updated by martinE-4 4 years, 9 months ago.

Assisted by: Nigel.

Author
Posts
#1492141

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

You are right, and it is not easy to fix it without a filter being made available by the Views developers to modify this.

It appears get_terms() is called four times on a page that contains a View with a single taxonomy filter (which is why the pre_get_terms hook is fired four times).

Unfortunately, unlike an API filter such as wpv_filter_query, which provides the $view_id, $view_settings, and $view_args, so that it is possible to determine what triggered the filter, the built-in pre_get_terms hook includes details of the $query, but these offer little or no useful information about what called get_terms() for us to be able to target just the pre_get_terms call we need to modify.

So, while the code I provided is successfully able to narrow down the contents of the filter control to only include the required terms, it also evidently interferes with further get_terms calls Views appears to make when it comes to building and submitting the query.

Any solution would require going through the $query object available to pre_get_terms to see if it is possible to isolate the specific calls to get_terms that we need to modify while avoiding changing the rest.

You could do that, or... yes, wait for the developers to add a filter to customise the filter content.

#1492535

My issue is resolved now. Thank you! I'll wait for the upcoming update to solve this pre-filter issue.