Make WordPress Core

Ticket #14426: 14426.2.patch

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

     
    26152615
    26162616                if ( 'ids' == $q['fields'] ) {
    26172617                        $this->posts = $wpdb->get_col($this->request);
     2618                        $this->set_found_posts( $q, $limits );
    26182619
    26192620                        return $this->posts;
    26202621                }
    26212622
    26222623                if ( 'id=>parent' == $q['fields'] ) {
    26232624                        $this->posts = $wpdb->get_results($this->request);
     2625                        $this->set_found_posts( $q, $limits );
    26242626
    26252627                        $r = array();
    26262628                        foreach ( $this->posts as $post )
     
    26422644                        $ids = $wpdb->get_col( $this->request );
    26432645
    26442646                        if ( $ids ) {
     2647                                $this->posts = $ids;
    26452648                                $this->set_found_posts( $q, $limits );
    26462649                                _prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] );
    2647                                 $this->posts = $ids;
    26482650                        } else {
    26492651                                $this->posts = array();
    2650                                 $this->found_posts = $this->max_num_pages = 0;
    26512652                        }
    26522653                } else {
    26532654                        $this->posts = $wpdb->get_results( $this->request );
     
    27702771        function set_found_posts( $q, $limits ) {
    27712772                global $wpdb;
    27722773
    2773                 if ( $q['no_found_rows'] || empty( $limits ) )
     2774                if ( $q['no_found_rows'] || ! $this->posts )
    27742775                        return;
    27752776
    2776                 $this->found_posts = $wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) );
     2777                if ( ! empty( $limits ) )
     2778                        $this->found_posts = $wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) );
     2779                else
     2780                        $this->found_posts = count( $this->posts );
     2781
    27772782                $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) );
    27782783
    2779                 $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] );
     2784                if ( ! empty( $limits ) )
     2785                        $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] );
    27802786        }
    27812787
    27822788        /**