From f0064e4969735822ff7282f565c0e759abcc02b5 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Fri, 24 Dec 2021 15:06:03 +0400 Subject: [PATCH 1/3] Post Content: Reflect changes when previewing post --- packages/block-library/src/post-content/index.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/post-content/index.php b/packages/block-library/src/post-content/index.php index 400e3068dfa0a9..3bf782a321e986 100644 --- a/packages/block-library/src/post-content/index.php +++ b/packages/block-library/src/post-content/index.php @@ -40,7 +40,10 @@ function render_block_core_post_content( $attributes, $content, $block ) { the_post(); } - $content = get_the_content( null, false, $post_id ); + // When inside the main loop, we want to use queried object + // so that `the_preview` for the current post can apply. + // We force this behavior by passing `null` instead of the post ID. + $content = get_the_content( null, false, in_the_loop() ? null : $post_id ); /** This filter is documented in wp-includes/post-template.php */ $content = apply_filters( 'the_content', str_replace( ']]>', ']]>', $content ) ); unset( $seen_ids[ $post_id ] ); From c6faf07245f089dda42199c521859476d3b8280b Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Fri, 24 Dec 2021 16:09:59 -0500 Subject: [PATCH 2/3] Fix title preview, use global post object --- packages/block-library/src/post-title/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/post-title/index.php b/packages/block-library/src/post-title/index.php index 61618939cec9dd..56302864265165 100644 --- a/packages/block-library/src/post-title/index.php +++ b/packages/block-library/src/post-title/index.php @@ -20,7 +20,7 @@ function render_block_core_post_title( $attributes, $content, $block ) { } $post_ID = $block->context['postId']; - $title = get_the_title( $post_ID ); + $title = get_the_title(); if ( ! $title ) { return ''; From 851a0bcd69d619f77738f1d6115fee3070fe089e Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Tue, 28 Dec 2021 14:29:57 +0400 Subject: [PATCH 3/3] Remove third argument from get_the_content --- packages/block-library/src/post-content/index.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/post-content/index.php b/packages/block-library/src/post-content/index.php index 3bf782a321e986..7edb2cd604a719 100644 --- a/packages/block-library/src/post-content/index.php +++ b/packages/block-library/src/post-content/index.php @@ -36,14 +36,16 @@ function render_block_core_post_content( $attributes, $content, $block ) { $seen_ids[ $post_id ] = true; + // 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(); } // When inside the main loop, we want to use queried object // so that `the_preview` for the current post can apply. - // We force this behavior by passing `null` instead of the post ID. - $content = get_the_content( null, false, in_the_loop() ? null : $post_id ); + // We force this behavior by omitting the third argument (post ID) from the `get_the_content`. + $content = get_the_content( null, false ); /** This filter is documented in wp-includes/post-template.php */ $content = apply_filters( 'the_content', str_replace( ']]>', ']]>', $content ) ); unset( $seen_ids[ $post_id ] );