#58031 closed defect (bug) (reported-upstream)
query-no-result block is always appeared if post-template block contains post-featured-image block
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 6.2 |
| Component: | Themes | Keywords: | |
| Focuses: | Cc: |
Description
If followings is in archive template:
<!-- wp:query {"query":{"perPage":1,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true}} -->
<div class="wp-block-query">
<!-- wp:post-template -->
<!-- wp:post-title /-->
<!-- wp:post-featured-image /-->
<!-- /wp:post-template -->
<!-- wp:query-no-results -->
<!-- wp:paragraph -->
<p>Not found.</p>
<!-- /wp:paragraph -->
<!-- /wp:query-no-results -->
</div>
<!-- /wp:query -->
<p>Not found.</p> always appeared, even if in non-empty archive page.
If query-no-results block is moved before post-template block, it works as expected.
If post-featured-image block is removed from post-template block, it works as expected too.
post-template block renders posts loop with cloned $wp_query
post-featured-image block render has followings:
// Check is needed for backward compatibility with third-party plugins
// that might rely on the `in_the_loop` check; calling `the_post` sets it to true.
if ( ! in_the_loop() && have_posts() ) {
the_post();
}
It is not in_the_loop() here, because cloned $wp_query is in_the_loop==true, but global $wp_query is not.
If the code block is removed, it works as expected.
Something mismatched, post-template should not clone $wp_query, or post-featured-image should set in_the_loop=true with different way?
Change History (7)
#3
@
3 years ago
MacOS
Chrome
WordPress 6.2
With and without Gutenberg 15.5.0
nginx
PHP 7.4.3.0
Testing result:
I can reproduce this in Twenty Twenty-Three if there is exactly one search result.
No template or markup changes are needed to test this.
Create a new post with a unique word that you know is not used anywhere in your content.
On the front, perform a search for the word (as in, use the search form and enter the keyword to do the search :) )
The post, as well as this text shows: "Sorry, but nothing matched your search terms. Please try again with some different keywords."
-This is the text that TT3 adds to the search inside the query no results block.
Create a second post with the same word, and search again.
The message does not show. The result is displayed correctly.
#4
@
3 years ago
Since this involves blocks, this ticket should be closed as "reported upstream" and we can continue discussions on the issue that Torsten @zodiac1978 created here https://github.com/WordPress/gutenberg/issues/49575
#6
@
3 years ago
This is the first report (mine was a duplicate too):
https://github.com/WordPress/gutenberg/issues/47793
One more important reproducible point is that archive page has just one post,
then
have_posts()reaches end of loop, and followinghave_posts()istrue.Maybe,
qurery-no-resultsblock should not usehave_posts(),$found_postsinstead?