#41246 closed enhancement (fixed)
Filter to short circuit term query 'terms_pre_query'
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.3 | Priority: | normal |
Severity: | normal | Version: | 4.6 |
Component: | Taxonomy | Keywords: | has-patch has-unit-tests has-dev-note |
Focuses: | Cc: |
Description
It would be nice to be able to effectively short-circuit a terms query so that you could return results from an external data source (WP_Query
already has a filter like this in the form of posts_pre_query
). My patch would add a similar filter terms_pre_query
into the ::parse_query()
method of the WP_Term_Query
class.
This is more a proof of concept than anything else, I'm not sure if it makes sense to leave the burden of handling term caching as well as the hide_empty and the pad_counts parameters on the callback function. Hopefully some more experienced contributors will have some better insight into that.
Attachments (4)
Change History (20)
#1
@
8 years ago
- Summary changed from Filter to short circuit term query to Filter to short circuit term query 'terms_pre_query'
#3
@
6 years ago
- Keywords has-patch added
- Version set to 4.6
Updated the patch. 41246.2.diff to be more similar to #44169.
Looping @adamsilverstein as he owned that.
#5
@
6 years ago
Thanks @spacedmonkey this looks good to me.
@boonebgorges when you have a chance, can you review 41246.2.diff and the code path in get_terms
. As. This looks good to me, however I'm uncertain whether we need to be concerned about priming caches with returned data or updating term counts.
#6
@
6 years ago
Thanks for the ping, @adamsilverstein . 41246.2.diff seems OK to me. Regarding caching, I'd say that core should definitely not be caching the results of short-circuited queries - this kind of "pre" filter hands over all such responsibilities to the plugin.
I'm not sure what you mean by "updating term counts". Do you mean _update_post_term_count()
etc? These are not term counts but *object-in-term* counts, and they don't touch the WP_Term_Query
results. (They do depend on the term_taxonomy_id
from WP's database tables, but again, any plugin using this filter is going to have to figure out how to reconcile this information on its own.) Or by "term counts" do you mean get_terms( fields=count )
? In this case too, I'd say that the terms_pre_query callback will just have to be smart enough to detect 'count' queries and return the right results - not much that we can do in core.
#7
@
6 years ago
- Keywords has-unit-tests added
- Milestone changed from Future Release to 5.3
- Owner set to adamsilverstein
- Status changed from new to assigned
Update the patch with 41246.3.diff. This is basically a copy and paste from #45749.
I have assigned this to @adamsilverstein to review. But I would also like feedback from @boonebgorges .
#9
@
6 years ago
@jarocks and @spacedmonkey nice work here! Thanks for reviewing @boonebgorges its very comforting having your feedback.
I appreciate how concise the code is. The docs for this can also be simpler than other pre- filters since there aren't pagination details or counts to update.
All tests are passing - https://travis-ci.com/WordPress/wordpress-develop/builds/117558388 - I'm going to do some more local testing, then get this committed!
#10
@
6 years ago
41246.4.diff slight whitespace cleanup. remove references to sites.
This ticket was mentioned in Slack in #core by justinahinon. View the logs.
5 years ago
#16
@
5 years ago
- Keywords has-dev-note added; commit needs-dev-note removed
This was detailed in the following dev note: https://make.wordpress.org/core/2019/04/11/new-network-and-sites-query-filters/.
Hi @jarocks - Thanks for the ticket! I like the idea.
For reference, #36687 was the ticket that introduced
posts_pre_query
.I'm unsure off the top of my head how best to handle all the post-query-processing that happens in
WP_Term_Query
. By way of comparison,WP_Query
continues to perform all of its ownpost_status
post-processing on posts provided by external data sources. We want to try to strike a balance between total customizability on the one hand, and giving developers all the conveniences of core queries on the other.As a way forward, could I suggest that you write a sample implementation? It's fine to use dummy data, of course. But I think it would be very helpful to get a sense of how the filter would work best. Ideally, the dummy data would be hierarchical, so we can get a sense of how count padding etc would work in practice. Since the data doesn't like in WP, it's likely that the callback function will *have* to handle all of this stuff, but it'll be a helpful exercise to see this in practice.