[wp-trac] [WordPress Trac] #58154: Twenty Twenty-Three uses query block incorrectly

WordPress Trac noreply at wordpress.org
Tue Apr 18 18:53:56 UTC 2023


#58154: Twenty Twenty-Three uses query block incorrectly
---------------------------+-----------------------
 Reporter:  flixos90       |       Owner:  flixos90
     Type:  defect (bug)   |      Status:  assigned
 Priority:  normal         |   Milestone:  6.3
Component:  Bundled Theme  |     Version:  6.1
 Severity:  normal         |  Resolution:
 Keywords:  needs-patch    |     Focuses:
---------------------------+-----------------------
Description changed by flixos90:

Old description:

> I recently noticed several problems related to how the WordPress query
> loop is handled in block themes, which partially comes down to the core
> implementation itself, but also to incorrect usage in e.g. the default
> theme Twenty Twenty-Three.
>
> Concretely:
> * TT3 is not using the `core/query` and `core/post-template` blocks in
> its `page.html` and `single.html` template. While that may intuitively
> seem like the right thing to do since these templates only display a
> single post, it is not: It has always been a best practice to always go
> through the query loop (i.e. `while( have_posts() ) { the_post(); ...
> }`), classic themes have always been doing that - check e.g. TT1's
> `page.php` and `single.php` for reference.
> * Not going through the query loop leads to several problems as the loop
> is never started, which apparently were so far were partially addressed
> by workarounds in Gutenberg, e.g. automatically starting the loop when in
> the `core/post-content` block, or similarly later in the `core/post-
> featured-image` block. These are workarounds though that lead to other
> bugs like #58027.
> * Additionally, wherever TT3 uses the `core/query` block, it includes
> parameters that customize the query, which should not happen as those
> templates should simply use the global main query, similar to how the
> equivalent classic themes would do it. In other words, all usages of the
> `core/query` block should solely set `{"query":{"inherit": true}}` and no
> other "query"-specific parameters (layout parameters are okay of course).
>
> There are a few other related aspects that need to be fixed in core &
> Gutenberg directly, but as a starting point we need to use the
> `core/query` block correctly in TT3.

New description:

 I recently noticed several problems related to how the WordPress query
 loop is handled in block themes, which partially comes down to the core
 implementation itself, but also to incorrect usage in e.g. the default
 theme Twenty Twenty-Three.

 Concretely:
 * TT3 is not using the `core/query` and `core/post-template` blocks in its
 `page.html` and `single.html` template. While that may intuitively seem
 like the right thing to do since these templates only display a single
 post, it is not: It has always been a best practice to always go through
 the query loop (i.e. `while( have_posts() ) { the_post(); ... }`), classic
 themes have always been doing that - check e.g. TT1's `page.php` and
 `single.php` for reference.
 * Not going through the query loop leads to several problems as the loop
 is never started, which apparently were so far were partially addressed by
 workarounds in Gutenberg, e.g. automatically starting the loop when in the
 `core/post-content` block, or similarly later in the `core/post-featured-
 image` block. These are workarounds though that lead to other bugs like
 #58027.
 * Additionally, wherever TT3 uses the `core/query` block, it includes
 parameters that customize the query, which should not happen as those
 templates should use the global main query, similar to how the equivalent
 classic themes would do it. In other words, preferably all usages of the
 `core/query` block should solely set `{"query":{"inherit": true}}` and no
 other "query"-specific parameters (layout parameters are okay of course).
 * However, it appears that the Site Editor itself has no awareness of the
 global query, so omitting the additional parameters leads to problems
 there. As long as that is the case, it makes sense to keep the additional
 parameters, but at a minimum it has to be ensured that every `core/query`
 usage includes `query.inherit=true`, so that the global query is relied on
 in the frontend.

 There are a few other related aspects that need to be fixed in core &
 Gutenberg directly, but as a starting point we need to use the
 `core/query` block correctly in TT3.

--

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58154#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list