Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#58031 closed defect (bug) (reported-upstream)

query-no-result block is always appeared if post-template block contains post-featured-image block

Reported by: obache's profile obache 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)

#1 @obache
2 years ago

One more important reproducible point is that archive page has just one post,
then have_posts() reaches end of loop, and following have_posts() is true.

Maybe, qurery-no-results block should not use have_posts(), $found_posts instead?

#2 @zodiac1978
2 years ago

#58080 was marked as a duplicate.

#3 @poena
2 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.

Last edited 2 years ago by poena (previous) (diff)

#4 @poena
2 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

#5 @zodiac1978
2 years ago

  • Resolution set to reported-upstream
  • Status changed from new to closed

#6 @zodiac1978
2 years ago

This is the first report (mine was a duplicate too):
https://github.com/WordPress/gutenberg/issues/47793

#7 @desrosj
2 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.