[wp-trac] [WordPress Trac] #30846: Custom query using tag__in sets query_var tag_id

WordPress Trac noreply at wordpress.org
Sat Dec 27 03:37:36 UTC 2014


#30846: Custom query using tag__in sets query_var tag_id
-------------------------------+------------------------------
 Reporter:  philbirnie         |       Owner:
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Taxonomy           |     Version:  4.1
 Severity:  normal             |  Resolution:
 Keywords:  reporter-feedback  |     Focuses:
-------------------------------+------------------------------

Comment (by philbirnie):

 boonbbgorges - Thank you very much for the reply and unit test.  It is
 possible that I'm doing something out of context and that could be causing
 the issue.  If so, I'm sorry in advance for wasting everyone's time!

 === Setup ===

 * This is a completely clean install with no additional plugins.  I am
 using theme Twenty Fifteen.
 * I placed the custom query outlined above on a custom page template;
 again, so I could isolate the problem.   I have attached that file for
 reference.  I created a new page that uses this template and loaded the
 page.

 === Unit Test ===

 Thank you for the unit test - it looks like the first assertion in the
 unit test should cover the issue that I'm seeing because the first tag
 does not contain any posts.  I will install the test suite and verify that
 the test passes.


 === Query Issue ===

 It does indeed appear that the `term_id` (by way of `term_taxonomy_id`) is
 getting added to the query, assuming that `$query->request` is the actual
 request that fetches the posts.   Below is an echo of `$query->request`.
 You'll notice that `wp_term_relationships.term_taxonomy_id IN (5)` is
 added - and because there are no posts associated with `term_taxonomy_id`
 5, this results in an empty set.

  If I remove this from the query (and the subsequent `AND` of course), I
 get the results I would expect -- all posts associated with 3, 4 and 5.

 {{{
 SELECT SQL_CALC_FOUND_ROWS  wp_posts.ID FROM wp_posts  INNER JOIN
 wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
 INNER JOIN wp_term_relationships AS tt1 ON (wp_posts.ID = tt1.object_id)
 WHERE 1=1  AND (
   wp_term_relationships.term_taxonomy_id IN (5)
   AND
   tt1.term_taxonomy_id IN (3,4,5)
 ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish')
 GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10
 }}}

 I will report back after completing the testing.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/30846#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list