#16742 closed defect (bug) (fixed)
Meta query doesn't work with $wp_query->set()
Reported by: | scribu | Owned by: | |
---|---|---|---|
Milestone: | 3.1.1 | Priority: | normal |
Severity: | normal | Version: | 3.1 |
Component: | Query | Keywords: | has-patch dev-feedback needs-codex |
Focuses: | Cc: |
Description
The following doesn't work, apparently:
add_action( 'pre_get_posts', function( $query ) { $query->set('meta_key','oqp_guest_email'); $query->set('meta_value',$dummy_email); } );
Source: http://wordpress.org/support/topic/pre_get_posts-problem
Attachments (5)
Change History (29)
#2
@
14 years ago
I thing we're going to have to store the parsed meta_query in it's own property, like we do for the tax_query.
#5
@
14 years ago
- Keywords has-patch removed
That will cause duplicate meta queries:
query_posts( array( 'meta_key' => 'foo' ) );
After the final call to _parse_meta_query(), 'meta_query' will be:
Array ( [0] => Array ( [key] => foo ) [1] => Array ( [key] => foo ) )
#6
follow-up:
↓ 7
@
14 years ago
- Keywords has-patch added
16742.class.diff is a lot simpler than the diff suggests, but it's still a pretty big change for a point release.
#7
in reply to:
↑ 6
@
14 years ago
Replying to scribu:
16742.class.diff is a lot simpler than the diff suggests, but it's still a pretty big change for a point release.
For 3.1.1 maybe we can use hashing(like tax query) and use WP_Meta_Query in 3.2
#8
@
14 years ago
16742.hash.diff doesn't solve the original issue in this bug.
#9
@
14 years ago
Actually, it does fix the original bug, but it stomps the original 'meta_query', if it's set:
query_posts( array( 'meta_query' => array( array( 'key' => 'foo' ) ) ) );
#10
@
14 years ago
- Keywords dev-feedback added
After further testing, it seems to work as expected.
Maybe we should just leave it for 3.2, instead of using clever, yet contrived, workarounds like this.
#11
@
14 years ago
- Keywords needs-codex added
If moving to 3.2, add codex so that plugin/theme authors are notified of the changes.
#14
@
14 years ago
Yes, it is. I've expressed my opinion in #comment:10. Your call.
#15
@
14 years ago
- Milestone changed from 3.2 to 3.1.1
Only a committer should be making a decision to punt a regression.
#16
@
14 years ago
- Version set to 3.1
16742.hash.diff seems good for 3.1.1. We can leave this ticket open and consider scribu's fix for 3.2.
#17
@
14 years ago
That patch may be too much for 3.1.1. It eliminates the multiple md5/serialize calls and sets one query_vars_changed flag. Setting the hash in parse_tax_query() seemed odd now that it is applying to more places.
#20
@
14 years ago
I went ahead with the hash cleanup. Please review thoroughly. The hash is now computed at the end of parse_query() right before the parse_query action. It is computed again in get_posts() after pre_get_posts and fill_query_vars() have run. If the query vars hash changed via the parse_query or pre_get_posts actions then the query_vars_changed flag is set to true so that the tax and meta parsers know to do their thing again. There are no other filters or actions that run between when the hash is recomputed and when the taxonomy and meta queries are parsed again.
Tested with init, pre_get_posts, and parse_query hooks that exercised a variety of meta and tax queries via set() and get_posts() calls on the main query and newly instantiated queries.
#21
follow-up:
↓ 22
@
14 years ago
Looking at the current solution, I think it might have been safer to go with 16742.class.diff after all. :)
Also this one generates some invalid sql
sql query