Make WordPress Core

Opened 20 years ago

Closed 20 years ago

Last modified 20 years ago

#3598 closed defect (bug) (fixed)

query_posts produces SQL error when excluding empty category

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

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

  • Resolution → fixed
  • Status new → closed

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

#2 @foolswisdom
20 years ago

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