#16545 closed defect (bug) (fixed)
Direct WP_Query::get_posts() calls can break
Reported by: | nacin | Owned by: | |
---|---|---|---|
Milestone: | 3.1 | Priority: | highest omg bbq |
Severity: | blocker | Version: | 3.1 |
Component: | Query | Keywords: | has-patch needs-testing |
Focuses: | Cc: |
Description
global $wp_query; $wp_query->set('cat', '-13'); $posts = $wp_query->get_posts();
That worked in 3.0, and fails in 3.1. With parse_query() never getting called, now parsed_tax_query() never gets called. Previously enough logic was in get_posts() for this to work. It was inconsistent because parse_query() was circumvented, but it worked.
In IRC he planned out a strategy of sorts and Ryan is going to work up a patch later.
Attachments (4)
Change History (30)
#2
@
14 years ago
- Summary changed from Direct WP_Quey::get_posts() calls can break to Direct WP_Query::get_posts() calls can break
#4
@
14 years ago
I don't think this warrants 'blocker' status, but I guess that doesn't make much of a difference.
#6
@
14 years ago
"That worked in 3.0, and fails in 3.1."
@scribu: an unintentional regression is generally a blocker.
#7
@
14 years ago
My point was that, like ryan said, it shouldn't have worked ever. parse_query() and get_posts() should have been private from the beginning. (Captain Hindsight to the resque, I know.)
#8
@
14 years ago
Avoids calling init() from parse_query() and stomping query vars that have been set(). query() now handles init() and query/query_vars setup. The $query arg to parse_query() is now optional. It is never passed by core code and could probably be gotten rid of, but it is still handled in case a plugin is calling it directly for whatever mysterious reason.
Note that using the set(), get_posts() style requires running init() yourself if you want to do another query with the same query object . This was true in 3.0 as well.
#10
@
14 years ago
In get_posts(), $this->parsed_query is set to false, just after it's set to true in parse_query(). Is that intentional?
#11
@
14 years ago
Nevermind, of course it's intentional. But what's the point in having it? Less code = less bugs.
#14
@
14 years ago
$query = new WP_Query; $query->set('cat', 4); $posts = $query->get_posts();
With your patch all set()s are stomped.
#15
@
14 years ago
Do the query from an init hook. It will always fail. A query run after the big query that reuses the big query object could sometimes work (although anyone doing that really should call init() before hand). My patch should work either way.
#16
@
14 years ago
Testing should be done with a clean object and a dirty object that has already run a query.
#23
@
14 years ago
What's the latest on this? Appreciate everyone's work but kind of sucks that WP 3.1 was released with this as a known problem. Everyone who upgraded to 3.1 and had been excluding categories is now unintentionally polluting their public RSS feeds with unexpected content. This is the first time I've upgraded WordPress and regretted it :(.
Thanks in advance for the help.
Original report: http://wordpress.org/support/topic/wp_query-exclude-categories-not-working?replies=4