Make WordPress Core

Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#3598 closed defect (bug) (fixed)

query_posts produces SQL error when excluding empty category

Reported by: joefish's profile joefish Owned by:
Milestone: 2.1 Priority: normal
Severity: normal Version: 2.1
Component: General Keywords: query-posts
Focuses: Cc:

Description

When setting up the loop with query_posts, an SQL error is generated if an empty category is excluded. For example, if the category with the id 8 is empty, query_posts('cat=-8') produces:

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '8 AND (post_type = 'post' AND (post_status = 'publish' OR post_status = 'private' at line 1]
SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts LEFT JOIN wp_post2cat ON (wp_posts.ID = wp_post2cat.post_id) WHERE 1=1 8 AND (post_type = 'post' AND (post_status = 'publish' OR post_status = 'private')) GROUP BY wp_posts.ID ORDER BY post_date DESC LIMIT 0, 10

Change History (2)

#1 @ryan
18 years ago

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

(In [4754]) Fix SQL error when excluding empty cat. fixes #3598

#2 @foolswisdom
18 years ago

  • Milestone set to 2.1
Note: See TracTickets for help on using tickets.