[wp-trac] [WordPress Trac] #58111: Main loop is not working in some cases with "Post Featured Image" block
WordPress Trac
noreply at wordpress.org
Mon Apr 10 20:47:24 UTC 2023
#58111: Main loop is not working in some cases with "Post Featured Image" block
--------------------------+-----------------------------
Reporter: engahmeds3ed | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 6.2
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Steps to reproduce:
1. Create a post that has the block "Post Featured Image"
2. Use the following snippet
{{{#!php
<?php
add_action( 'wp_head', function () {
if ( ! is_singular() ) {
return;
}
$post = get_queried_object();
apply_filters( 'the_content', $post->post_content );
} );
}}}
3. Visit the created post page in frontent.
4. You will find the page content part is empty.
I believe this is because:
https://github.com/WordPress/wordpress-
develop/blob/07fc9b2d7449314ee658d764ce162e99cef6783b/src/wp-
includes/blocks/post-featured-image.php#L24-L26
We are outside the loop (inside wp_head hook), the function **the_post**
will be called and then **$wp_query->current_post** will be increased from
-1 to be 0 so the next loop (main content loop) will not fire because of
that.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/58111>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list