Make WordPress Core

Opened 11 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's profile prettyboymp Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Query Keywords: needs-patch needs-unit-tests early
Focuses: Cc:


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)

#1 @wonderboymusic
11 years ago

  • Keywords reporter-feedback added

Check out pre_get_posts and parse_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?

#2 @prettyboymp
11 years ago

  • Keywords reporter-feedback removed

The issues is places in WP_Query::get_posts() like 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:

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 @wonderboymusic
11 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

#4 @wonderboymusic
10 years ago

  • Keywords needs-unit-tests added
  • Milestone changed from Awaiting Review to Future Release

Will consider for this release if a patch materializes

#5 @chriscct7
9 years ago

  • Keywords early added
Note: See TracTickets for help on using tickets.