Make WordPress Core

Opened 15 months ago

Closed 15 months ago

Last modified 15 months ago

#57822 closed defect (bug) (fixed)

Query Loop block showing all posts when Sticky Posts set to "Only"

Reported by: ravanh's profile RavanH Owned by: hellofromtonya's profile 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 ocean90)

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)

Attachments (2)

trac57822-reproduce-bug-before-patch.gif (2.5 MB) - added by hellofromTonya 15 months ago.
Test Report: Able to reproduce the issue 🐞 (before applying PR 4144)
trac57822-after-patch.gif (485.9 KB) - added by hellofromTonya 15 months ago.
Test Report: applying PR 4144 resolves the issue ✅

Change History (15)

This ticket was mentioned in PR #4144 on WordPress/wordpress-develop by RavanH.


15 months ago
#1

  • Keywords has-patch added

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:

@sc0ttkclark commented on PR #4144:


15 months ago
#2

We ought to add a test for this for query block?

#3 @ocean90
15 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.


15 months ago

#6 @hellofromTonya
15 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:


15 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 @hellofromTonya
15 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 @hellofromTonya
15 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

  1. Add a new Post.
  2. Add a Query Loop block.
  3. Select "Start blank".
  4. Select first layout.
  5. Change "Sticky Posts" to "Only".
  6. Publish the post.
  7. 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.

@hellofromTonya
15 months ago

Test Report: Able to reproduce the issue 🐞 (before applying PR 4144)

@hellofromTonya
15 months ago

Test Report: applying PR 4144 resolves the issue ✅

#10 @hellofromTonya
15 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:

When testing the bugfix patch:

#11 @hellofromTonya
15 months ago

  • Keywords commit added

Patch: https://github.com/WordPress/wordpress-develop/pull/4144

Ready for commit 👍 Prepping it now

#12 @hellofromTonya
15 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 55447:

Editor: Exclude non-sticky posts in Query Loop Block when set to "Only".

Fixes a front-end issue to not include non-sticky posts in the Query Loop block when it's "Sticky Post" is set to "Only", meaning only show sticky posts.

This change was made in Gutenberg between 5.8 to 6.0, but was not merged into Core.

Reference:

Follow-up to [50945].

Props RavanH, sc0ttkclark, ocean90, sc0ttkclark, hellofromTonya, ntsekouras.
Fixes #57822.

Note: See TracTickets for help on using tickets.