Make WordPress Core

Ticket #18536: 18536.2.diff

File 18536.2.diff, 2.2 KB (added by scribu, 13 years ago)
  • wp-includes/query.php

    diff --git wp-includes/query.php wp-includes/query.php
    index bc6edea..cefe9ca 100644
    class WP_Query { 
    19511951                $fields = '';
    19521952                $post_status_join = false;
    19531953                $page = 1;
     1954                $expand_ids = false;
    19541955
    19551956                if ( isset( $q['caller_get_posts'] ) ) {
    19561957                        _deprecated_argument( 'WP_Query', '3.1', __( '"caller_get_posts" is deprecated. Use "ignore_sticky_posts" instead.' ) );
    class WP_Query { 
    25972598                                $$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] : '';
    25982599                }
    25992600
     2601                if ( "$wpdb->posts.*" == $fields ) {
     2602                        $fields = "$wpdb->posts.ID";
     2603                        $expand_ids = true;
     2604                }
     2605
    26002606                if ( ! empty($groupby) )
    26012607                        $groupby = 'GROUP BY ' . $groupby;
    26022608                if ( !empty( $orderby ) )
    class WP_Query { 
    26262632                        return $r;
    26272633                }
    26282634
    2629                 $this->posts = $wpdb->get_results($this->request);
     2635                if ( $expand_ids ) {
     2636                        $ids = $wpdb->get_col( $this->request );
     2637
     2638                        if ( $ids ) {
     2639                                if ( !$q['no_found_rows'] && !empty( $limits ) ) {
     2640                                        $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) );
     2641                                        $this->found_posts = $wpdb->get_var( $found_posts_query );
     2642                                        $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) );
     2643                                        $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']);
     2644                                }
     2645
     2646                                $query = sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s) $orderby", join( ",", $ids ) );
     2647                                $this->posts = $wpdb->get_results($query);
     2648                        } else {
     2649                                $this->found_posts = $this->max_num_pages = 0;
     2650                                $this->posts = array();
     2651                        }
     2652                } else {
     2653                        $this->posts = $wpdb->get_results($this->request);
     2654                }
    26302655
    26312656                // Raw results filter. Prior to status checks.
    26322657                if ( !$q['suppress_filters'] )
    class WP_Query { 
    26452670                        $this->comment_count = count($this->comments);
    26462671                }
    26472672
    2648                 if ( !$q['no_found_rows'] && !empty($limits) ) {
     2673                if ( !$q['no_found_rows'] && !empty($limits) && !$expand_ids ) {
    26492674                        $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) );
    26502675                        $this->found_posts = $wpdb->get_var( $found_posts_query );
    26512676                        $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) );