#57822 closed defect (bug) (fixed)
Query Loop block showing all posts when Sticky Posts set to "Only"
Reported by: | RavanH | Owned by: | hellofromTonya |
---|---|---|---|
Milestone: | 6.2 | Priority: | normal |
Severity: | normal | Version: | 5.8 |
Component: | Editor | Keywords: | has-patch gutenberg-merge has-testing-info commit |
Focuses: | Cc: |
Description (last modified by )
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:
- Create a test page with the Query Loop block, set the parameter Sticky Posts to "Only".
- 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)
Attachments (2)
Change History (15)
This ticket was mentioned in PR #4144 on WordPress/wordpress-develop by RavanH.
20 months ago
#1
- Keywords has-patch added
@sc0ttkclark commented on PR #4144:
20 months ago
#2
We ought to add a test for this for query block?
#3
@
20 months ago
- Description modified (diff)
- Version changed from trunk to 5.8
I noticed that in Gutenberg this case is/was handled but it seems like it was never backported to core?
This ticket was mentioned in Slack in #core-editor by ocean90. View the logs.
20 months ago
@hellofromTonya commented on PR #4144:
20 months ago
#5
Commits https://github.com/WordPress/wordpress-develop/pull/4144/commits/526d9b1d853165f539f3bf05a684c063057d856b and https://github.com/WordPress/wordpress-develop/pull/4144/commits/2164f1f199ef8d5b56da0294a8accc5c353fd668 bring full parity with the changes in Gutenberg https://github.com/WordPress/gutenberg/blob/42dad571eac32c41a7ff34f0da80fcc4e5ceb3bd/lib/compat/wordpress-6.1/blocks.php#L171-L183 to synchronize Core and Gutenberg.
#6
@
20 months ago
- Keywords gutenberg-merge added
- Milestone changed from Awaiting Review to 6.2
- Owner set to hellofromTonya
- Status changed from new to reviewing
Good catch @ocean90!
Marking this ticket as a gutenberg-merge
as PR 4144 synchronizes the changes from Gutenberg into Core.
Self-assigning for commit review.
@ntsekouras commented on PR #4144:
20 months ago
#7
Just for reference, the function will be under `6.2` compat folder , since we are including this change now.
So some links for GB in comments would be different.
#8
@
20 months ago
- Component changed from Query to Editor
Changing the component to Editor as this is bug is related to the Query Loop block, rather than to the Query component.
#9
@
20 months ago
- Keywords has-testing-info added
Testing Instructions
These steps define how to reproduce the issue, and indicate the expected behavior.
Steps to Reproduce
- Add a new Post.
- Add a Query Loop block.
- Select "Start blank".
- Select first layout.
- Change "Sticky Posts" to "Only".
- Publish the post.
- View in the front-end. 🐞 Notice all of the non-sticky posts are showing.
Expected Results
When testing a patch to validate it works as expected:
- ✅ In the front-end, non-sticky posts should not show.
When reproducing a bug:
- ❌ In the front-end, the non-sticky posts are showing.
Test Report Icons:
🐞 <= Indicates where issue ("bug") occurs.
✅ <= Behavior is expected.
❌ <= Behavior is NOT expected.
#10
@
20 months ago
Test Report
Patch tested: https://github.com/WordPress/wordpress-develop/pull/4144
Environment
- OS: macOS
- WordPress: trunk
- Localhost: wp-env (Docker)
- Plugins: none
- Theme: TT3
- Browser: Chrome
Actual Results
When reproducing a bug/defect:
- ❌ As trac57822-reproduce-bug-before-patch.gif shows, able to reproduce the issue in the front-end.
When testing the bugfix patch:
- ✅ As trac57822-after-patch.gif shows, the patch resolves the issue.
#11
@
20 months ago
- Keywords commit added
Patch: https://github.com/WordPress/wordpress-develop/pull/4144
- Confirmed the changes match the changes in Gutenberg ✅
- Test Report confirms this patch fixes the reported issue ✅
Ready for commit 👍 Prepping it now
@hellofromTonya commented on PR #4144:
20 months ago
#13
Committed via https://core.trac.wordpress.org/changeset/55447.
This fixes the issue where all non-sticky posts show up in the Query Loop block when Sticky Posts is set to "Only" and there are no sticky posts.
Additional
(array)
typecast for safety.See https://core.trac.wordpress.org/ticket/57822
Trac ticket: