Make WordPress Core

Opened 16 years ago

Closed 16 years ago

#15161 closed defect (bug) (fixed)

categories aren't excluded by pre_get_posts

Reported by: jorbin Owned by: scribu
Priority: normal Milestone: 3.1
Component: Query Version: 3.1
Severity: blocker Keywords: needs-patch regression
Cc: Focuses:

Description

Using a filter such as:

function jorbin_exclude_category($query) {
	if ( $query->is_feed || $query->is_home ) {
		$query->set('cat', '-9,-2,-8,-25,-13');
	}
	return $query;
}

add_filter('pre_get_posts', 'jorbin_exclude_category');

Fails on trunk, but works on 3.0.1 . It sets the category properly, but the posts aren't filtered out, so I hesitate to blame #14494

Change History (6)

#1 @scribu
16 years ago

  • Owner set to scribu
  • Status new → reviewing
  • Summary catagories aren't be excluded by pre_get_posts → categories aren't excluded by pre_get_posts

#2 @jane
16 years ago

  • Keywords needs-patch added

#3 @scribu
16 years ago

  • Status reviewing → accepted

This is because all the taxonomy related queries are parsed in parse_query() and put into the 'taxonomy_query' query var.

PS: 'pre_get_posts' is an action, not a filter.

#4 @nacin
16 years ago

  • Keywords regression added
  • Severity normal → blocker

#5 @scribu
16 years ago

The solution would be to re-parse all the query vars before calling get_tax_sql().

#6 @scribu
16 years ago

  • Resolution → fixed
  • Status accepted → closed

(In [16380]) Re-parse tax query just before calling get_tax_sql(). Fixes #15161

Note: See TracTickets for help on using tickets.