[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:52 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:6 shahabdev]:
 > By using tax_query, you explicitly tell WordPress to retrieve posts that
 match any of the specified categories without introducing unnecessary
 joins. This should help maintain a consistent SQL structure before and
 after calling get_posts(), preventing the restrictive filtering you’re
 experiencing.
 >
 If the issue persists, you can also try debugging the SQL query further by
 running $articles_query->request inside functions.php or a custom debug
 function. This can help pinpoint whether WordPress is modifying the query
 elsewhere. However, using tax_query should be the most effective way to
 fix the problem and ensure that all posts from the selected categories are
 retrieved correctly.

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


More information about the wp-trac mailing list