[wp-trac] [WordPress Trac] #59225: Block themes do not trigger "the loop" correctly

WordPress Trac noreply at wordpress.org
Mon Aug 28 15:35:18 UTC 2023


#59225: Block themes do not trigger "the loop" correctly
--------------------------+-----------------------------------------
 Reporter:  flixos90      |      Owner:  flixos90
     Type:  defect (bug)  |     Status:  assigned
 Priority:  high          |  Milestone:  6.4
Component:  Editor        |    Version:
 Severity:  normal        |   Keywords:  needs-patch gutenberg-merge
  Focuses:                |
--------------------------+-----------------------------------------
 Currently, block themes do not handle "the loop" correctly. Since their
 existence, WordPress themes have been expected to have the main `WP_Query`
 object go through the loop of posts when rendering posts. This ensures the
 WordPress query loop is correctly handled, e.g. calling `in_the_loop()`
 will return `true` as expected.

 In block themes, this doesn't happen correctly though, the loop is not
 started when rendering posts which breaks the long-standing expectation
 that is relied on in both WP core and the plugin ecosystem. This is
 because the `core/post-template` block, when configured to use the global
 query (via the `inherit` attribute), _clones_ the global query object
 rather than using it directly. This leads to the main query loop never
 being started since it is only started on the cloned instance.

 The only reason this isn't ''entirely'' broken is a workaround in the
 `core/post-content` and `core/post-featured-image` blocks which forces the
 loop to start if it hasn't started yet. However, that itself is not a
 proper fix as it does not cover all `core/post-*` blocks (e.g. when
 rendering posts with only a title and date it wouldn't work), and more
 importantly introduces bugs on its own, such as #58027.

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


More information about the wp-trac mailing list