WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#15161 closed defect (bug) (fixed)

categories aren't excluded by pre_get_posts

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

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)

comment:1 @scribu4 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

comment:2 @jane4 years ago

  • Keywords needs-patch added

comment:3 @scribu4 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.

comment:4 @nacin4 years ago

  • Keywords regression added
  • Severity changed from normal to blocker

comment:5 @scribu4 years ago

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

comment:6 @scribu4 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.