#38589 closed defect (bug) (fixed)
hook 'get_terms_args' calls two times ...
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 4.7 | Priority: | normal |
| Severity: | normal | Version: | 4.6 |
| Component: | Taxonomy | Keywords: | |
| Focuses: | Cc: |
Description
There is no logic situation in new WP_Term_Query class
Look into get_terms() method - it calls $this->parse_query( $this->query_vars );. When parse_query call hook 'get_terms_args' a after it get_terms() itself calls hook
'get_terms_args' one more time.
So in one request we have double hook calls...
It seems like bug!
link to class: https://developer.wordpress.org/reference/classes/wp_term_query/
Change History (5)
#1
@
9 years ago
- Component changed from General to Taxonomy
- Focuses administration removed
- Milestone changed from Awaiting Review to 4.7
- Version changed from 4.6.1 to 4.6
#2
@
9 years ago
@boonebgorges: I must have accidentally introduced it. I agree that the occurrence in WP_Term_Query::parse_query() should be removed, since the name of the filter indicates it is used when get_terms() is run and furthermore since other query classes don't have such a filter in their parse_query() method.
Good catch @Tkama!
#3
@
9 years ago
- Owner set to boonebgorges
- Resolution set to fixed
- Status changed from new to closed
In 39057:
#4
@
9 years ago
If I understand correctly, since r39057, the query vars of WP_Term_Query cannot be modified when parsing them on a standalone query object (when not calling get_terms()), right? This is because the query object in the parse_term_query and pre_get_terms actions isn't provided by reference (which is the case in the similar hooks in WP_Query).
#5
@
9 years ago
Hi @Offereins - In contexts like the following, the query object is passed by reference as the default behavior in PHP 5+:
do_action( 'parse_term_query', $this );
Instances of &$this in the codebase are a remnant of PHP 4 support.
(We've already spoken about this over Slack, but I wanted to repeat it here for posterity :) )
Hi @Tkama - Thank you for the ticket, and welcome to WordPress Trac!
You're correct that it's illogical to call the 'get_terms_args' filter twice. This problem was introduced in [37572] along with
WP_Term_Query. I believe that the error can be explained like this: Prior to [37572], 'get_terms_args' had been applied inget_terms(), after the defaults had been set up. (This usage dates back many versions.) Butparse_query()seems, in some abstract sense, like the "right" place for the filter to live, which is why I assume it was introduced in [37572].I think the correct fix is to remove the 'get_terms_args' filter in
WP_Term_Query::parse_query(), but I'd like a second opinion on that before moving forward. @flixos90, since you drafted the original patch, could I ask for your thoughts?