[wp-trac] [WordPress Trac] #63255: WP_Query normalization can break plugin filters comparing query variables.

WordPress Trac noreply at wordpress.org
Tue Apr 8 23:20:46 UTC 2025


#63255: WP_Query normalization can break plugin filters comparing query variables.
---------------------------+--------------------
 Reporter:  peterwilsoncc  |      Owner:  (none)
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  6.8
Component:  Query          |    Version:
 Severity:  normal         |   Keywords:
  Focuses:                 |
---------------------------+--------------------
 The `WP_Query` normalization changes in #59516 to improve cache hits can
 break plugins applying filters to secondary/custom end point queries based
 on query var values.

 As an example:

 {{{#!php
 <?php
 $query = new WP_Query( array( 'post_type' => array( 'post', 'page' ) ) );

 add_filter( 'posts_where', function ( $where, $query ) {
         if ( array( 'post', 'page' ) === $query->get( 'post_type' ) ) {
                 // Modify WHERE clause.
         }

         return $where;
 }, 10, 2 );
 }}}

 In 6.7 the above filter would modify the WHERE clause, in 6.8 the clause
 would not be modified as the post type value has been normalized to
 `array( 'page', 'post' )`.

 A real world example can be seen in
 [https://bbpress.trac.wordpress.org/browser/trunk/src/includes/replies/functions.php?marks=2094-2097#L2094
 bbpress's filtering of the WHERE clause] generated by `bbp_has_replies()`.

 Props @vortfu, @jjj

 If the decision is made to revert, the about page will need to be updated
 to delete the "Take a load off the database" section referencing these
 changes.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63255>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list