Make WordPress Core

Opened 2 years ago

Last modified 5 months ago

#55745 new defect (bug)

FSE post-content block is using wrong "first" item in the query loop

Reported by: trekky's profile Trekky Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.9.3
Component: Themes Keywords: close
Focuses: Cc:

Description

Hey,

I've created a block based theme for a Full-Site-Editing experience and noticed the following problem:

I would like to show only posts from a specific category on the frontpage and created a template with the following content (simplified):

<!-- wp:template-part {"slug":"header","tagName":"header","className":"site-header"} /-->
test
<!-- wp:group {"tagName":"main","layout":{"inherit":true}} -->
<main class="wp-block-group">
	<!-- wp:query {"queryId":0,"query":{"perPage":10,"pages":0,"offset":0,"postType":"post","categoryIds":[7],"tagIds":[],"order":"desc","orderBy":"date","search":"","exclude":[],"sticky":"","inherit":false}} -->
	<div class="wp-block-query">
		<!-- wp:post-template -->
			<!-- wp:post-title {"isLink":true} /-->
			<!-- wp:post-content /-->
		<!-- /wp:post-template -->
	<!-- /wp:query -->
</main>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","tagName":"footer","className":"site-footer"} /-->

When using the block "post-content" the wrong post content is shown. When using post-excerpt the correct excerpt is used.
Apparently the problem lies in the post-content.php file (https://github.com/WordPress/WordPress/blob/aeb3b7530af57db885dfa8f377a7c6aa22e309bd/wp-includes/blocks/post-content.php#L42) where

the_post() 

is called.
When this call is removed everything is working as expected. It seems this workaround for "third-party plugins" doesn't handle all edge cases.
In this case the latest post on the whole site is saved as the_post() instead of the latest post of the query.

I hope someone gets a solution for the problem.

Thank you very much!

Change History (1)

#1 @poena
5 months ago

  • Keywords close added

Hi
I am not able to reproduce this.
The example code for the query loop above is not valid when I try to add it to a template in WordPress 6.5.2 (there is a block validation error).

If I add a new query loop to the home template in the site Editor, and then go to the Filter settings and choose a category, both the post content block and the excerpt block show the correct content.

This issue may have been valid two years ago when it was created, but it seems to have been solved since then.

Note: See TracTickets for help on using tickets.