Opened 7 years ago

Closed 7 years ago

#2709 closed defect (bug) (fixed)

Category query cleanups

Reported by: skeltoac Owned by: skeltoac
Priority: high Milestone: 2.1
Component: Administration Version: 2.0.2
Severity: major Keywords: category query
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 7 years ago.

Download all attachments as: .zip

Change History (5)

Um, DISTINCT.

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?

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.

comment:4   ryan7 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.