Opened 3 years ago
Closed 3 weeks ago
#55745 closed defect (bug) (worksforme)
FSE post-content block is using wrong "first" item in the query loop
Reported by: | Trekky | Owned by: | |
---|---|---|---|
Milestone: | 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 (2)
#2
@
3 weeks ago
- Milestone Awaiting Review deleted
- Resolution set to worksforme
- Status changed from new to closed
I am also unable to replicate this. I am therefore going to progress through in closing this based on the suggestion and my testing. Thank you for reporting and the good news seems to be it looks like it has been resolved. If however, you are still experiencing this we can always have a new issue or reopen with more details.
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.