Make WordPress Core

Opened 14 years ago

Closed 14 years ago

#15161 closed defect (bug) (fixed)

categories aren't excluded by pre_get_posts

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


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
14 years ago

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

#2 @jane
14 years ago

  • Keywords needs-patch added

#3 @scribu
14 years ago

  • Status changed from reviewing to 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
14 years ago

  • Keywords regression added
  • Severity changed from normal to blocker

#5 @scribu
14 years ago

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

#6 @scribu
14 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

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

Note: See TracTickets for help on using tickets.