Make WordPress Core

Ticket #14426: 14426.3.patch

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

     
    26142614                }
    26152615
    26162616                if ( 'ids' == $q['fields'] ) {
    2617                         $this->posts = $wpdb->get_col($this->request);
     2617                        $this->posts = $wpdb->get_col( $this->request );
     2618                        $this->post_count = count( $this->posts );
     2619                        $this->set_found_posts( $q, $limits );
    26182620
    26192621                        return $this->posts;
    26202622                }
    26212623
    26222624                if ( 'id=>parent' == $q['fields'] ) {
    2623                         $this->posts = $wpdb->get_results($this->request);
     2625                        $this->posts = $wpdb->get_results( $this->request );
     2626                        $this->post_count = count( $this->posts );
     2627                        $this->set_found_posts( $q, $limits );
    26242628
    26252629                        $r = array();
    26262630                        foreach ( $this->posts as $post )
     
    26422646                        $ids = $wpdb->get_col( $this->request );
    26432647
    26442648                        if ( $ids ) {
     2649                                $this->posts = $ids;
    26452650                                $this->set_found_posts( $q, $limits );
    26462651                                _prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] );
    2647                                 $this->posts = $ids;
    26482652                        } else {
    26492653                                $this->posts = array();
    2650                                 $this->found_posts = $this->max_num_pages = 0;
    26512654                        }
    26522655                } else {
    26532656                        $this->posts = $wpdb->get_results( $this->request );
     
    27502753                if ( !$q['suppress_filters'] )
    27512754                        $this->posts = apply_filters_ref_array('the_posts', array( $this->posts, &$this ) );
    27522755
    2753                 $this->post_count = count($this->posts);
     2756                $this->post_count = count( $this->posts );
    27542757
    27552758                // Always sanitize
    27562759                foreach ( $this->posts as $i => $post ) {
     
    27702773        function set_found_posts( $q, $limits ) {
    27712774                global $wpdb;
    27722775
    2773                 if ( $q['no_found_rows'] || empty( $limits ) )
     2776                if ( $q['no_found_rows'] || ! $this->posts )
    27742777                        return;
    27752778
    2776                 $this->found_posts = $wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) );
     2779                if ( ! empty( $limits ) )
     2780                        $this->found_posts = $wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) );
     2781                else
     2782                        $this->found_posts = count( $this->posts );
     2783
    27772784                $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) );
    27782785
    2779                 $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] );
     2786                if ( ! empty( $limits ) )
     2787                        $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] );
    27802788        }
    27812789
    27822790        /**