Make WordPress Core

Ticket #14426: 14426.4.patch

File 14426.4.patch, 2.8 KB (added by SergeyBiryukov, 13 years ago)
  • wp-includes/query.php

     
    979979        var $comment;
    980980
    981981        /**
    982          * Amount of posts if limit clause was not used.
     982         * The amount of found posts for the current query.
    983983         *
     984         * If limit clause was not used, equals $post_count.
     985         *
    984986         * @since 2.1.0
    985987         * @access public
    986988         * @var int
     
    26302632                }
    26312633
    26322634                if ( 'ids' == $q['fields'] ) {
    2633                         $this->posts = $wpdb->get_col($this->request);
     2635                        $this->posts = $wpdb->get_col( $this->request );
     2636                        $this->post_count = count( $this->posts );
     2637                        $this->set_found_posts( $q, $limits );
    26342638
    26352639                        return $this->posts;
    26362640                }
    26372641
    26382642                if ( 'id=>parent' == $q['fields'] ) {
    2639                         $this->posts = $wpdb->get_results($this->request);
     2643                        $this->posts = $wpdb->get_results( $this->request );
     2644                        $this->post_count = count( $this->posts );
     2645                        $this->set_found_posts( $q, $limits );
    26402646
    26412647                        $r = array();
    26422648                        foreach ( $this->posts as $post )
     
    26582664                        $ids = $wpdb->get_col( $this->request );
    26592665
    26602666                        if ( $ids ) {
     2667                                $this->posts = $ids;
    26612668                                $this->set_found_posts( $q, $limits );
    26622669                                _prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] );
    2663                                 $this->posts = $ids;
    26642670                        } else {
    26652671                                $this->posts = array();
    2666                                 $this->found_posts = $this->max_num_pages = 0;
    26672672                        }
    26682673                } else {
    26692674                        $this->posts = $wpdb->get_results( $this->request );
     
    27662771                if ( !$q['suppress_filters'] )
    27672772                        $this->posts = apply_filters_ref_array('the_posts', array( $this->posts, &$this ) );
    27682773
    2769                 $this->post_count = count($this->posts);
     2774                $this->post_count = count( $this->posts );
    27702775
    27712776                // Always sanitize
    27722777                foreach ( $this->posts as $i => $post ) {
     
    27832788                return $this->posts;
    27842789        }
    27852790
     2791        /**
     2792         * Set up the amount of found posts and the number of pages (if limit clause was used)
     2793         * for the current query.
     2794         *
     2795         * @since 3.5.0
     2796         * @access private
     2797         */
    27862798        function set_found_posts( $q, $limits ) {
    27872799                global $wpdb;
    27882800
    2789                 if ( $q['no_found_rows'] || empty( $limits ) )
     2801                if ( $q['no_found_rows'] || ! $this->posts )
    27902802                        return;
    27912803
    2792                 $this->found_posts = $wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) );
     2804                if ( ! empty( $limits ) )
     2805                        $this->found_posts = $wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) );
     2806                else
     2807                        $this->found_posts = count( $this->posts );
     2808
    27932809                $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) );
    27942810
    2795                 $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] );
     2811                if ( ! empty( $limits ) )
     2812                        $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] );
    27962813        }
    27972814
    27982815        /**