#9268 closed defect (bug) (duplicate)
WP_Query->query() fails when both 'cat' and 'tag' parameters are specified
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | |
| Component: | General | Keywords: | |
| Focuses: | Cc: |
Description
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)
WHERE 1=1
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
Related ticket:5433