Repository navigation
Query: Add With Results block, the inverse of No Results - #83125
vedant-ere wants to merge 7 commits into
Conversation
Mirrors core/query-no-results but renders its inner blocks only when the query has matching posts, so a heading, Post Template, and pagination can be grouped and hidden together when a Query Loop has nothing to show. Purely additive -- existing Query Loops are untouched.
Follow-up to the With Results block addition -- this generated file was missed in that commit.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
🤖 PR meta 🤖🏷️ LabelsThis pull request needs exactly one label indicating its type, and has 0.
Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you. |
|
Hey 👋 I wanted to give you a heads-up since this pull request is affected by recent validation changes for changelog files. #83043 adds additional validation for changelog files. You'll note that this pull request is currently failing a "Required changes from trunk" check. What you'll need to do: You will need to either rebase or merge the latest code from |
…results' into feature/query-loop-hide-when-no-results
What?
See #83029
Related: #53316
Adds a new
core/query-with-resultsblock — a container that only renders its inner blocks when the Query Loop it lives in has matching posts. It's the mirror image of the existingcore/query-no-resultsblock.Why?
core/query-no-resultsfor showing a fallback message when a query returns nothing — that part already works today.No ResultsandPost Templateare the only two blocks that actually know whether the query found anything. A Heading, Paragraph, or any other block placed alongside them has no such awareness and always renders, no matter what.No Resultsalone still leaves an awkward result: a heading (or intro text) shows above an apology that there's nothing under it.Post TemplateandNo Resultsalready have. This PR adds that.How?
core/query-with-resultsreuses the exact same mechanismcore/query-no-resultsalready uses — sameancestorrestriction (only insertable inside Query Loop), same per-instance query check — just with the condition inverted: it renders when the query has posts instead of when it doesn't.It's a plain container, not a single-purpose message block, so it can hold a heading, Post Template, Pagination, or anything else together as one group. It defaults to Post Template + Pagination when inserted, since that's the common case, but nothing stops you from putting other blocks inside too.
This is purely additive: no existing Query Loop is changed or migrated. It's a new block available in the inserter for anyone who wants this grouping behavior.
Testing Instructions
Note: if you add "With Results" to a Query Loop that already has a standalone Post Template/Pagination sitting outside it, you'll get duplicate posts — both will render since they share the same query context. Move the existing Post Template/Pagination inside "With Results," or delete them and let its own default template take over.
Screenshots
Both screenshots use the same query (filtered to match zero posts). The only difference is whether the heading is wrapped in "With Results" or sitting as a plain sibling.
Use of AI Tools
This PR was developed with Claude Code : research into the issue and prior work, and the automated tests listed above were AI-assisted.