Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#3598 closed defect (bug) (fixed)

query_posts produces SQL error when excluding empty category

Reported by: joefish Owned by: anonymous
Priority: normal Milestone: 2.1
Component: General Version: 2.1
Severity: normal Keywords: query-posts
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)

comment:1   ryan6 years ago

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

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

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