[wp-trac] [WordPress Trac] #62401: WP_Query add extra JOINs after calling get_posts() with category__in in query arguments

WordPress Trac noreply at wordpress.org
Fri Feb 7 07:23:05 UTC 2025


#62401: WP_Query add extra JOINs after calling get_posts() with category__in in
query arguments
--------------------------+------------------------------
 Reporter:  elancerteam   |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Query         |     Version:  6.6.2
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by shahabdev):

 Replying to [comment:3 shahabdev]:
 > The extra LEFT JOIN clauses (tt1 and tt2) indicate that WordPress is
 applying additional filtering logic. This usually happens when multiple
 categories are involved, and WP_Query attempts to enforce a strict match.
 Instead of simply retrieving posts belonging to any of the specified
 categories, it sometimes assumes that posts must belong to all categories
 in the array.
 >
 This behavior is influenced by how category__in is processed internally.
 When you pass multiple category IDs, WP_Query may attempt to refine the
 results further using multiple joins, sometimes restricting the posts to
 those that belong to only the first category in the array. This can lead
 to unexpected filtering behavior, as seen in your SQL output.

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


More information about the wp-trac mailing list