Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify check for no posts in query-no-results block #53772

Merged

Conversation

ocean90
Copy link
Member

@ocean90 ocean90 commented Aug 17, 2023

What?

Replace have_posts() check with the post_count property to workaround queries which haven't rewinded properly.

Why?

Fixes #47793.

How?

Instead of setting up the query loop, just check if post count is > 0 and bail.

Testing Instructions

See #47793.

Testing Instructions for Keyboard

Screenshots or screencast

@ocean90 ocean90 added [Block] Query Loop Affects the Query Loop Block [Block] No Results Affects the No Results Block - used when a Query Loop returns no results labels Aug 17, 2023
@ocean90 ocean90 added the [Type] Bug An existing feature does not function as intended label Aug 17, 2023
Copy link
Member

@mikachan mikachan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works well for me!

Before After
Screenshot 2023-08-18 at 13 44 56 Screenshot 2023-08-18 at 13 46 04

Before approving, I have one question about the post_count property, which I've left an inline comment about.

@mikachan mikachan added the [Package] Block library /packages/block-library label Aug 25, 2023
@ocean90 ocean90 merged commit 324e9b3 into trunk Aug 30, 2023
54 of 57 checks passed
@ocean90 ocean90 deleted the fix/query-no-results-showing-even-if-query-has-results branch August 30, 2023 07:05
@github-actions github-actions bot added this to the Gutenberg 16.6 milestone Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] No Results Affects the No Results Block - used when a Query Loop returns no results [Block] Query Loop Affects the Query Loop Block [Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No Results block shows when there is 1 search result
2 participants