Opened 12 years ago
Last modified 5 years ago
#23309 new defect (bug)
Not all WP_Query::query_vars get updated during WP_Query::get_posts()
Reported by: | prettyboymp | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Query | Keywords: | needs-patch needs-unit-tests early |
Focuses: | Cc: |
Description
There is a lot of logic within the WP_Query::get_posts() method that fills in missing query vars with defaults and manipulates others based on the rest of the query. However, some of the final states for many of the variables aren't updated in the WP_Query::query_vars array. For example, the post type is lost as a local variable and post_status is used for building compiling mysql expressions, but never directly updated.
The result is that any plugins that want to recreate the query for another system, (ie, an external search provider) must directly copy much of the business logic that WP_Query::get_posts() has embedded in it in order to fill in for the incomplete query_var array.
Change History (5)
#2
@
12 years ago
- Keywords reporter-feedback removed
The issues is places in WP_Query::get_posts() like http://core.trac.wordpress.org/browser/trunk/wp-includes/query.php#L2222 use additional logic to build the post_type clauses but never update the query_vars with the outcome. Similar things are happening in this block for post_status: http://core.trac.wordpress.org/browser/trunk/wp-includes/query.php#L2437.
In my specific use case, I'm trying to build a boolean query to send to Amazon CloudSearch. However, at no point during the WP_Query process are the query_vars in an absolute state. My only option is to copy/paste the logic from WP_Query::get_posts() to my plugin to fill in these gaps.
#3
@
12 years ago
- Keywords needs-patch added
Ok, yes, I agree that one (tax slurping all post types) sucks, and I voiced my objections about it right after it got changed in core. To defeat that, simply pass 'post' as post_type or whatever post_types you are trying to query. It only happens when you don't explicitly pass a post_type. The documentation for this is misleading and caused me pain as well, especially since it is ignorant of multisite.
I think this is patchable - I'll take a look
Check out
pre_get_posts
andparse_query
filters - might be a better way to slurp the data you are looking for. Do you have some code in a Gist or something that can show what you are trying to accomplish?