WordPress.org

Make WordPress Core

Ticket #19608: core.patch

File core.patch, 2.3 KB (added by FrederickTownes, 6 years ago)
  • wp-includes/query.php

    diff --git wp-includes/query.php wp-includes/query.php
    index d70348c..e34b942 100644
    class WP_Query { 
    26002600                if ( !$q['no_found_rows'] && !empty($limits) )
    26012601                        $found_rows = 'SQL_CALC_FOUND_ROWS';
    26022602
    2603                 $this->request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";
    2604                 if ( !$q['suppress_filters'] )
     2603        $ids_request = "SELECT $found_rows $distinct {$wpdb->posts}.ID FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";
     2604        $ids_res = $wpdb->get_results($ids_request);
     2605
     2606        if ( !$q['no_found_rows'] && !empty($limits) ) {
     2607                        $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) );
     2608                        $this->found_posts = $wpdb->get_var( $found_posts_query );
     2609                        $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) );
     2610                        $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']);
     2611                }
     2612
     2613        $ids_list = array();
     2614        foreach ( $ids_res as $id_row ) {
     2615            $ids_list[] = $id_row->ID;
     2616        }
     2617        $ids_where = " AND 0";
     2618        if ( count($ids_list) > 0 ) {
     2619            $ids_where = " AND {$wpdb->posts}.ID IN (" . implode(',', $ids_list) . ")";
     2620        }
     2621       
     2622                $this->request = " SELECT $distinct $fields FROM $wpdb->posts WHERE 1=1 $ids_where $orderby";
     2623        if ( !$q['suppress_filters'] )
    26052624                        $this->request = apply_filters_ref_array('posts_request', array( $this->request, &$this ) );
    26062625
    26072626                if ( 'ids' == $q['fields'] ) {
    class WP_Query { 
    26392658                        $this->comment_count = count($this->comments);
    26402659                }
    26412660
    2642                 if ( !$q['no_found_rows'] && !empty($limits) ) {
    2643                         $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) );
    2644                         $this->found_posts = $wpdb->get_var( $found_posts_query );
    2645                         $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) );
    2646                         $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']);
    2647                 }
    2648 
    26492661                // Check post status to determine if post should be displayed.
    26502662                if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) {
    26512663                        $status = get_post_status($this->posts[0]);