WordPress.org

Make WordPress Core

Ticket #42256: 42256.2.diff

File 42256.2.diff, 1.5 KB (added by dlh, 21 months ago)
  • src/wp-includes/class-wp-query.php

     
    19171917                } elseif ( $q['post__in'] ) {
    19181918                        $post__in = implode(',', array_map( 'absint', $q['post__in'] ));
    19191919                        $where .= " AND {$wpdb->posts}.ID IN ($post__in)";
     1920
     1921                        // Don't count found rows when a specific range is requested.
     1922                        if ( isset( $q['posts_per_page'] ) && count( $q['post__in'] ) === (int) $q['posts_per_page'] ) {
     1923                                $q['no_found_rows'] = true;
     1924                        }
    19201925                } elseif ( $q['post__not_in'] ) {
    19211926                        $post__not_in = implode(',',  array_map( 'absint', $q['post__not_in'] ));
    19221927                        $where .= " AND {$wpdb->posts}.ID NOT IN ($post__not_in)";
  • tests/phpunit/tests/query/noFoundRows.php

     
    8686                $this->assertNotContains( 'SQL_CALC_FOUND_ROWS', $q->request );
    8787                $this->assertSame( 1, $q->found_posts );
    8888        }
     89
     90        /**
     91         * @ticket 42256
     92         */
     93        public function test_no_found_rows_true_when_post__in_count_matches_posts_per_page() {
     94                $post_ids = $this->factory->post->create_many( 3 );
     95
     96                $q = new WP_Query( array(
     97                        'post__in' => $post_ids,
     98                        'posts_per_page' => count( $post_ids ),
     99                ) );
     100
     101                $this->assertNotContains( 'SQL_CALC_FOUND_ROWS', $q->request );
     102        }
    89103}