Skip to content

Commit 99d837a

Browse files
authored
Post excerpt > Ensure the postId from the block context is used to get_the_excerpt (WordPress#49495)
* ensure the postId from the block context to get_the_excerpt instead of relying on the global post object. * Restructure the code for get_the_excerpt * phpcs: Align equal sign
1 parent bdedc58 commit 99d837a

File tree

1 file changed

+3
-3
lines changed
  • packages/block-library/src/post-excerpt

1 file changed

+3
-3
lines changed

packages/block-library/src/post-excerpt/index.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ function render_block_core_post_excerpt( $attributes, $content, $block ) {
2525
* wp_trim_words is used instead.
2626
*/
2727
$excerpt_length = $attributes['excerptLength'];
28+
$excerpt = get_the_excerpt( $block->context['postId'] );
2829
if ( isset( $excerpt_length ) ) {
29-
$excerpt = wp_trim_words( get_the_excerpt(), $excerpt_length );
30-
} else {
31-
$excerpt = get_the_excerpt();
30+
$excerpt = wp_trim_words( $excerpt, $excerpt_length );
3231
}
32+
3333
$more_text = ! empty( $attributes['moreText'] ) ? '<a class="wp-block-post-excerpt__more-link" href="' . esc_url( get_the_permalink( $block->context['postId'] ) ) . '">' . wp_kses_post( $attributes['moreText'] ) . '</a>' : '';
3434
$filter_excerpt_more = function( $more ) use ( $more_text ) {
3535
return empty( $more_text ) ? $more : '';

0 commit comments

Comments
 (0)