[wp-trac] [WordPress Trac] #57822: Query Loop block showing all posts when Sticky Posts set to "Only"

WordPress Trac noreply at wordpress.org
Tue Feb 28 14:02:03 UTC 2023


#57822: Query Loop block showing all posts when Sticky Posts set to "Only"
--------------------------+-----------------------------
 Reporter:  RavanH        |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 When the Query Loop block has the option "Sticky Posts" set to "Only" and
 there are NO posts marked as Sticky, the block will show all the latest
 (non-sticky) posts.

 This is related to the VERY old bug
 https://core.trac.wordpress.org/ticket/28099 where an empty array passed
 to 'post__in' is ignored and the query variable is treated as not set.

 The bug is set to WONTFIX because fixing it would break too many plugins.
 It now it affects the Query Loop block.

 To reproduce:
 1. Create a test page with the Query Loop block, set the parameter Sticky
 Posts to "Only".
 2. Make sure there are NO posts marked as Sticky.

 Expected result: no posts on the test page.

 Found result: all latest non-sticky posts on the test page.

 This filter will fix the issue:

 {{{
 add_filter( 'query_loop_block_query_vars', function( $query ) {
         if ( isset( $query['post__in'] ) && ! $query['post__in'] ) {
                 $query['post__in'] = [0];
         }
         return $query;
 } );
 }}}

 (since there is no Blocks component (yet?), I've filed this ticket against
 the Query component)

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


More information about the wp-trac mailing list