Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#9268 closed defect (bug) (duplicate)

WP_Query->query() fails when both 'cat' and 'tag' parameters are specified

Reported by: Nick Higgs Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:


WP_Query->query() will always return no posts if both the 'cat' and 'tag' parameters are specified.

Examing the query generated, it appears that this is because the term related tables are only joined once, rather than twice for both categories and tags. e.g.

SELECT 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)
INNER JOIN wp_terms ON (wp_term_taxonomy.term_id = wp_terms.term_id)
AND wp_term_taxonomy.taxonomy = 'category'
AND wp_term_taxonomy.term_id IN ('15')
AND wp_term_taxonomy.taxonomy = 'post_tag'
AND wp_terms.slug IN ('my-tag-slug')
AND wp_posts.post_type = 'post'
AND (wp_posts.post_status = 'publish')
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date DESC

Change History (3)

#2 @Denis-de-Bernardy
9 years ago

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

closing as dup of #5433 and #8987

#3 @Denis-de-Bernardy
9 years ago

  • Milestone Unassigned deleted
Note: See TracTickets for help on using tickets.