Skip to content

Commit

Permalink
Ensure post-featured-image block is in_the_loop() for BC with core an…
Browse files Browse the repository at this point in the history
…d plugins. (#45534)
  • Loading branch information
felixarntz authored Nov 16, 2022
1 parent 5f53eaf commit 799c416
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/block-library/src/post-featured-image/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ function render_block_core_post_featured_image( $attributes, $content, $block )
}
$post_ID = $block->context['postId'];

// Check is needed for backward compatibility with third-party plugins
// that might rely on the `in_the_loop` check; calling `the_post` sets it to true.
if ( ! in_the_loop() && have_posts() ) {
the_post();
}

$is_link = isset( $attributes['isLink'] ) && $attributes['isLink'];
$size_slug = isset( $attributes['sizeSlug'] ) ? $attributes['sizeSlug'] : 'post-thumbnail';
$post_title = trim( strip_tags( get_the_title( $post_ID ) ) );
Expand Down

0 comments on commit 799c416

Please sign in to comment.