3 | | Concretely: |
4 | | * 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. |
5 | | * 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. |
6 | | * 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). |
7 | | * 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. |
| 3 | Related, yet a different problem is #59225. As part of that ticket, the workaround found in the `core/post-content` and `core/post-featured-image` blocks is removed accordingly, however that is not a coherent fix to the problem anyway. |
9 | | 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. |
| 5 | To test: |
| 6 | 1. Use Twenty Twenty-Three. |
| 7 | 2. In the Site Editor, update the `single` post template to not display the `core/post-featured-image` and `core/post-content` blocks. |
| 8 | 3. Add the below PHP code snippet to your WP installation. |
| 9 | 4. View a single post and notice the "in the loop: false" text. |
| 10 | 5. After applying the PR https://github.com/WordPress/wordpress-develop/pull/5104 to your WP installation and refreshing the URL, you should see "in the loop: true". |
| 11 | |
| 12 | {{{#!php |
| 13 | add_filter( |
| 14 | 'render_block_core/post-title', |
| 15 | function( $block_content ) { |
| 16 | return $block_content . '<p>in the loop: ' . ( in_the_loop() ? 'true' : 'false' ) . '</p>'; |
| 17 | } |
| 18 | ); |
| 19 | }}} |