From 47c492b11488721a6a82368e69e0411b0d13a4c4 Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Wed, 1 Mar 2023 16:15:18 +0000 Subject: [PATCH] Editor: Exclude non-sticky posts in Query Loop Block when set to "Only". Fixes a front-end issue to not include non-sticky posts in the Query Loop block when it's "Sticky Post" is set to "Only", meaning only show sticky posts. This change was made in Gutenberg between 5.8 to 6.0, but was not merged into Core. Reference: * [https://github.com/WordPress/gutenberg/blob/42dad571eac32c41a7ff34f0da80fcc4e5ceb3bd/lib/compat/wordpress-6.1/blocks.php#L171-L183 Gutenberg code] Follow-up to [50945]. Props RavanH, sc0ttkclark, ocean90, sc0ttkclark, hellofromTonya, ntsekouras. Fixes #57822. Built from https://develop.svn.wordpress.org/trunk@55447 git-svn-id: http://core.svn.wordpress.org/trunk@54980 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/blocks.php | 10 +++++++++- wp-includes/version.php | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index 5b8871d3f7..9a8c3b06f4 100644 --- a/wp-includes/blocks.php +++ b/wp-includes/blocks.php @@ -1265,7 +1265,15 @@ function build_query_vars_from_query_block( $block, $page ) { if ( isset( $block->context['query']['sticky'] ) && ! empty( $block->context['query']['sticky'] ) ) { $sticky = get_option( 'sticky_posts' ); if ( 'only' === $block->context['query']['sticky'] ) { - $query['post__in'] = $sticky; + /* + * Passing an empty array to post__in will return have_posts() as true (and all posts will be returned). + * Logic should be used before hand to determine if WP_Query should be used in the event that the array + * being passed to post__in is empty. + * + * @see https://core.trac.wordpress.org/ticket/28099 + */ + $query['post__in'] = ! empty( $sticky ) ? $sticky : array( 0 ); + $query['ignore_sticky_posts'] = 1; } else { $query['post__not_in'] = array_merge( $query['post__not_in'], $sticky ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 4f2a5c5f95..6e43f7d503 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.2-beta3-55446'; +$wp_version = '6.2-beta3-55447'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.