From f36c7ed33ca56cbe422ca5e64091a51ee1b9f100 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Wed, 3 Mar 2021 18:00:50 +0200 Subject: [PATCH 1/2] Print nothing if there are no results in Query block --- packages/block-library/src/query-loop/index.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/block-library/src/query-loop/index.php b/packages/block-library/src/query-loop/index.php index 053ebda29a2e2..476df8ad338ff 100644 --- a/packages/block-library/src/query-loop/index.php +++ b/packages/block-library/src/query-loop/index.php @@ -57,6 +57,10 @@ function render_block_core_query_loop( $attributes, $content, $block ) { )->render( array( 'dynamic' => false ) ); $content .= "
  • {$block_content}
  • "; } + + if ( ! $content ) { + return ''; + } return sprintf( '', $wrapper_attributes, From d2472f36733757a38b646edb17a7ed8831d5e84d Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Thu, 4 Mar 2021 12:36:59 +0200 Subject: [PATCH 2/2] move empty check up in code --- packages/block-library/src/query-loop/index.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/block-library/src/query-loop/index.php b/packages/block-library/src/query-loop/index.php index 476df8ad338ff..293ad681ff0f0 100644 --- a/packages/block-library/src/query-loop/index.php +++ b/packages/block-library/src/query-loop/index.php @@ -34,7 +34,11 @@ function render_block_core_query_loop( $attributes, $content, $block ) { } } - $posts = get_posts( $query ); + $posts = get_posts( $query ); + if ( empty( $posts ) ) { + return ''; + } + $classnames = ''; if ( isset( $block->context['layout'] ) && isset( $block->context['query'] ) ) { if ( isset( $block->context['layout']['type'] ) && 'flex' === $block->context['layout']['type'] ) { @@ -58,9 +62,6 @@ function render_block_core_query_loop( $attributes, $content, $block ) { $content .= "
  • {$block_content}
  • "; } - if ( ! $content ) { - return ''; - } return sprintf( '', $wrapper_attributes,