Opened 3 months ago
Last modified 7 weeks ago
#23469 new defect (bug)
Comment meta query is parsed before the pre_get_comments filter
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 3.6 |
| Component: | Comments | Version: | 3.5 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | kaspars@…, info@… |
Description
Currently it is impossible to use the pre_get_comments filter to adjust the meta_query, because parse_query_vars( $this->query_vars ) is run before the filter is applied http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/comment.php#L243:
// Parse meta query $this->meta_query = new WP_Meta_Query(); $this->meta_query->parse_query_vars( $this->query_vars ); do_action_ref_array( 'pre_get_comments', array( &$this ) );
Comment meta query should be parsed after the pre_get_comments filter has been applied.
Attachments (1)
Change History (10)
comment:3
follow-up:
↓ 6
SergeyBiryukov — 3 months ago
- Version changed from 3.5.1 to 3.5
comment:4
SergeyBiryukov — 3 months ago
- Keywords reporter-feedback added
- Severity changed from major to normal
Replying to nacin:
Seems like WP_Query has opposite behavior.
WP_Query parses the meta query after the 'pre_get_posts' gets applied: http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/query.php#L1934. And it makes sense, because you would need to manually run $query->meta_query->parse_query_vars( $query->query_vars ); every time you modify something related to the meta query.
Replying to SergeyBiryukov:
The suggested patch would make $this->meta_query object inaccessible for the hooked functions.
Exactly, just like WP_Query doesn't make the parsed meta_query available on pre_get_posts.
In your pre_get_posts filters you don't have to manually parse_query to actually apply the changes, so it shouldn't be required for changes to meta_query either.
comment:7
SergeyBiryukov — 3 months ago
- Keywords reporter-feedback removed
- Milestone changed from Awaiting Review to 3.6
comment:8
follow-up:
↓ 9
markjaquith — 7 weeks ago
This was odd to me. https://gist.github.com/markjaquith/681af58ce22d79c08c09
But moving it would be a breaking change. Maybe we should just have another hook that happens before parsing.
But moving it would be a breaking change.
I think parse_query_vars for meta_query already takes care of double parsing, in case somebody is doing it manually on pre_get_comments.
Maybe we should just have another hook that happens before parsing.
That could be a solution, but it would make the pre_get_ filters inconsistent.

Move the pre_get_comments filter before the meta_query parser