diff --git a/packages/block-library/src/post-template/index.php b/packages/block-library/src/post-template/index.php index 45bf3c4c64602e..2b0bb6503952b2 100644 --- a/packages/block-library/src/post-template/index.php +++ b/packages/block-library/src/post-template/index.php @@ -36,10 +36,6 @@ function render_block_core_post_template( $attributes, $content, $block ) { $query = new WP_Query( $query_args ); - if ( ! $query->have_posts() ) { - return ''; - } - $classnames = ''; if ( isset( $block->context['displayLayout'] ) && isset( $block->context['query'] ) ) { if ( isset( $block->context['displayLayout']['type'] ) && 'flex' === $block->context['displayLayout']['type'] ) { @@ -49,6 +45,10 @@ function render_block_core_post_template( $attributes, $content, $block ) { $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classnames ) ); + if ( ! $query->have_posts() ) { + return "

" . __( 'No results found.' ) . '

'; + } + $content = ''; while ( $query->have_posts() ) { $query->the_post();