[wp-trac] [WordPress Trac] #58031: query-no-result block is always appeared if post-template block contains post-featured-image block

WordPress Trac noreply at wordpress.org
Fri Mar 31 05:14:13 UTC 2023


#58031: query-no-result block is always appeared if post-template block contains
post-featured-image block
--------------------------+-----------------------------
 Reporter:  obache        |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Themes        |    Version:  6.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 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:
 {{{#!php
         // 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?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58031>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list