WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#9985 closed defect (bug) (fixed)

'category__and' stopped working

Reported by: jayant Owned by:
Milestone: 2.8 Priority: high
Severity: major Version: 2.8
Component: General Keywords:
Focuses: Cc:

Description

Operating System: Ubuntu 9.04
Webserver: Apache 2.2.11
PHP: 5.2.6
MySQL: 5.0.75
Wordpress Version: Nightly build 05/29/09 -> 2.8-beta2 changeset 11491

Works fine with Wordpress 2.7.1.

Steps to Reproduce:
1) Create two categories lets say catA (id: 3) and catB (id: 6).
2) Create a post with the two categories selected and publish it.
3) Modify the WP loop query in the theme to:
query_posts(array('categoryand'=>array(3,6), 'showposts'=>3));

Result:
No post show up in the WP loop.

SQL Query Log:
090530 12:32:22 40 Connect cb_wp_main@localhost on

40 Query SET NAMES utf8
40 Init DB cb_wp_main
40 Query SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes'
40 Query SELECT * FROM wp_users WHERE user_login = 'admin'
40 Query SELECT meta_key, meta_value FROM wp_usermeta WHERE user_id = 1
40 Query SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') ORDER BY wp_posts.post_date DESC LIMIT 0, 10
40 Query SELECT FOUND_ROWS()
40 Query SELECT t.*, tt.*, tr.object_id FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category', 'post_tag') AND tr.object_id IN (8, 5, 1) ORDER BY t.name ASC
40 Query SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN (8,5,1)
40 Query SELECT YEAR(post_date) AS year, MONTH(post_date) AS month, count(ID) as posts FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC
40 Query SELECT * FROM wp_posts WHERE (post_type = 'page' AND post_status = 'publish') AND ( ID <> 133 AND ID <> 113 ) ORDER BY menu_order ASC
40 Query SELECT option_value FROM wp_options WHERE option_name = 'page_for_posts' LIMIT 1
40 Query SELECT p.ID FROM wp_posts p INNER JOIN wp_term_relationships tr ON (p.ID = tr.object_id) INNER JOIN wp_term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) INNER JOIN wp_terms t ON (tt.term_id = t.term_id) WHERE tt.taxonomy = 'category' AND t.slug IN ('3', '6') GROUP BY p.ID HAVING count(p.ID) = 2
40 Query SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts WHERE 1=1 AND 0 = 1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') ORDER BY wp_posts.post_date DESC LIMIT 0, 3
40 Query SELECT FOUND_ROWS()
40 Query SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) WHERE 1=1 AND wp_term_taxonomy.taxonomy = 'category' AND wp_term_taxonomy.term_id IN ('4') AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 3
40 Query SELECT FOUND_ROWS()
40 Query SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) WHERE 1=1 AND wp_term_taxonomy.taxonomy = 'category' AND wp_term_taxonomy.term_id IN ('5', '6', '7', '8', '9') AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 7
40 Query SELECT FOUND_ROWS()
40 Query SELECT * FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 15
40 Query SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('category') ORDER BY t.name ASC
40 Query SELECT * , IF (DATE_ADD(link_updated, INTERVAL 120 MINUTE) >= NOW(), 1,0) as recently_updated FROM wp_links WHERE 1=1 AND link_visible = 'Y' ORDER BY wp_links.link_id ASC
40 Quit

Attachments (1)

9985.diff (777 bytes) - added by ryan 5 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 jayant5 years ago

  • Milestone changed from Unassigned to 2.8

comment:2 ryan5 years ago

[11348] is possibly related.

comment:3 ryan5 years ago

It's doing a slug instead of a term_id query, which suggest line 1916 is buggy.

ryan5 years ago

comment:4 ryan5 years ago

Quick patch, untested.

comment:5 ryan5 years ago

  • Priority changed from normal to high

comment:6 jayant5 years ago

Tried the fix. Solves the problem.

I did not test for regression issues.

comment:7 alysko5 years ago

diff works fine. Thank you !

comment:8 ryan5 years ago

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

(In [11501]) Use proper field for category intersection queries. fixes #9985

Note: See TracTickets for help on using tickets.