[wp-trac] [WordPress Trac] #57822: Query Loop block showing all posts when Sticky Posts set to "Only"
WordPress Trac
noreply at wordpress.org
Wed Mar 1 11:48:12 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: 5.8
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
--------------------------+------------------------------
Changes (by ocean90):
* version: trunk => 5.8
Old description:
> 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)
New description:
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 #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)
--
Comment:
I noticed that in
[https://github.com/WordPress/gutenberg/blob/42dad571eac32c41a7ff34f0da80fcc4e5ceb3bd/lib/compat/wordpress-6.1/blocks.php#L171-L183
Gutenberg this case is/was handled ] but it seems like it was never
backported to core?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/57822#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list