Make WordPress Core

Ticket #57416: 57416.diff

File 57416.diff, 2.7 KB (added by mkox, 2 years ago)

Patch checks for post per page == 1 before splitting the query

  • src/wp-includes/class-wp-query.php

    diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php
    index bdfce5e52c..3cc337933a 100644
    a b class WP_Query { 
    32693269               }
    32703270
    32713271               if ( null === $this->posts ) {
    3272                        $split_the_query = ( $old_request == $this->request && "{$wpdb->posts}.*" === $fields && ! empty( $limits ) && $q['posts_per_page'] < 500 );
     3272                       if ( $q['posts_per_page'] == 1 ) {
     3273                               $split_the_query = false;
     3274                       }
     3275                       else {
     3276                               $split_the_query = ( $old_request == $this->request && "{$wpdb->posts}.*" === $fields && ! empty( $limits ) && $q['posts_per_page'] < 500 );
    32733277
    3274                        /**
    3275                         * Filters whether to split the query.
    3276                         *
    3277                         * Splitting the query will cause it to fetch just the IDs of the found posts
    3278                         * (and then individually fetch each post by ID), rather than fetching every
    3279                         * complete row at once. One massive result vs. many small results.
    3280                         *
    3281                         * @since 3.4.0
    3282                         *
    3283                         * @param bool     $split_the_query Whether or not to split the query.
    3284                         * @param WP_Query $query           The WP_Query instance.
    3285                         */
    3286                        $split_the_query = apply_filters( 'split_the_query', $split_the_query, $this );
     3278                               /**
     3279                                * Filters whether to split the query.
     3280                                *
     3281                                * Splitting the query will cause it to fetch just the IDs of the found posts
     3282                                * (and then individually fetch each post by ID), rather than fetching every
     3283                                * complete row at once. One massive result vs. many small results.
     3284                                *
     3285                                * @since 3.4.0
     3286                                *
     3287                                * @param bool     $split_the_query Whether or not to split the query.
     3288                                * @param WP_Query $query           The WP_Query instance.
     3289                                */
     3290                               $split_the_query = apply_filters( 'split_the_query', $split_the_query, $this );
     3291                       }
     3292
    32873293
    32883294                       if ( $split_the_query ) {
    32893295                               // First get the IDs and then fill in the objects.