Make WordPress Core

Changeset 55447


Ignore:
Timestamp:
03/01/2023 04:13:15 PM (20 months ago)
Author:
hellofromTonya
Message:

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:

Follow-up to [50945].

Props RavanH, sc0ttkclark, ocean90, sc0ttkclark, hellofromTonya, ntsekouras.
Fixes #57822.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks.php

    r55446 r55447  
    12661266            $sticky = get_option( 'sticky_posts' );
    12671267            if ( 'only' === $block->context['query']['sticky'] ) {
    1268                 $query['post__in'] = $sticky;
     1268                /*
     1269                 * Passing an empty array to post__in will return have_posts() as true (and all posts will be returned).
     1270                 * Logic should be used before hand to determine if WP_Query should be used in the event that the array
     1271                 * being passed to post__in is empty.
     1272                 *
     1273                 * @see https://core.trac.wordpress.org/ticket/28099
     1274                 */
     1275                $query['post__in']            = ! empty( $sticky ) ? $sticky : array( 0 );
     1276                $query['ignore_sticky_posts'] = 1;
    12691277            } else {
    12701278                $query['post__not_in'] = array_merge( $query['post__not_in'], $sticky );
Note: See TracChangeset for help on using the changeset viewer.