Make WordPress Core

Opened 19 years ago

Closed 19 years ago

#2709 closed defect (bug) (fixed)

Category query cleanups

Reported by: skeltoac's profile skeltoac Owned by: skeltoac's profile skeltoac
Milestone: 2.1 Priority: high
Severity: major Version: 2.0.2
Component: Administration Keywords: category query
Focuses: Cc:

Description

Category queries concatenate category_id conditions.

How about doing it this way:

?cat=1,2,3,-4,-5,6,-8,-9

 AND category_id IN (1, 2, 3, 6) AND category_id NOT IN (4, 5, 8, 9)

We also need to put UNIQUE back in due to the way JOIN returns one row for every matching post2cat record.

Attachments (1)

category-query.diff (3.5 KB) - added by skeltoac 19 years ago.

Download all attachments as: .zip

Change History (5)

#1 @skeltoac
19 years ago

Um, DISTINCT.

#2 @skeltoac
19 years ago

Due to the JOIN, NOT IN can fail in this circumstance: a post is in two categories, one of which is not in the NOT IN list. The usual case here is that a post is in categores "Parent" and "Child", and the excluded category is "Child." In this case, the post will appear because the JOIN returns a row with the the category_id of Parent, which is not an excluded category.

I think this is acceptable. Any argument?

#3 @skeltoac
19 years ago

Patch attached. I also changed the field list to

apply_filters('posts_fields', "$wpdb->posts.*");

which returns fewer columns (none from JOINed tables) and makes DISTINCT work. If anybody knows of a need for JOINed columns, speak now.

#4 @ryan
19 years ago

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

(In [3767]) Category query cleanups from skeltoac. fixes #2709

Note: See TracTickets for help on using tickets.