From 4a72d5af01204d8e98887852929bdcebbeffadc3 Mon Sep 17 00:00:00 2001 From: Carolina Nymark Date: Wed, 20 Oct 2021 06:34:42 +0200 Subject: [PATCH 1/2] Return early if sticky posts are set to only, but there are no sticky posts. --- packages/block-library/src/post-template/index.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/block-library/src/post-template/index.php b/packages/block-library/src/post-template/index.php index 45bf3c4c64602e..76008ffa16c2f2 100644 --- a/packages/block-library/src/post-template/index.php +++ b/packages/block-library/src/post-template/index.php @@ -15,6 +15,14 @@ * @return string Returns the output of the query, structured using the layout defined by the block's inner blocks. */ function render_block_core_post_template( $attributes, $content, $block ) { + + // Return early if sticky posts are set to only, but there are no sticky posts. + if ( isset( $block->context['query']['sticky'] ) + && 'only' === $block->context['query']['sticky'] + && empty( get_option( 'sticky_posts' ) ) ) { + return ''; + } + $page_key = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page'; $page = empty( $_GET[ $page_key ] ) ? 1 : (int) $_GET[ $page_key ]; From 4e0b7571c6fb748643cf02627744d266a69f7491 Mon Sep 17 00:00:00 2001 From: Carolina Nymark Date: Wed, 20 Oct 2021 06:52:51 +0200 Subject: [PATCH 2/2] Do not display duplicate sticky posts in the paged result. --- packages/block-library/src/post-template/index.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/block-library/src/post-template/index.php b/packages/block-library/src/post-template/index.php index 76008ffa16c2f2..2ba112674b2c0a 100644 --- a/packages/block-library/src/post-template/index.php +++ b/packages/block-library/src/post-template/index.php @@ -60,6 +60,10 @@ function render_block_core_post_template( $attributes, $content, $block ) { $content = ''; while ( $query->have_posts() ) { $query->the_post(); + // Do not display duplicate sticky posts in the paged result. + if ( $page > 1 && is_sticky() ) { + continue; + } $block_content = ( new WP_Block( $block->parsed_block,