Ticket #18536: 18536.diff

File 18536.diff, 2.7 KB (added by ryan, 21 months ago)
  • wp-includes/query.php

     
    19401940                $fields = ''; 
    19411941                $post_status_join = false; 
    19421942                $page = 1; 
     1943                $expand_ids = false; 
    19431944 
    19441945                if ( isset( $q['caller_get_posts'] ) ) { 
    19451946                        _deprecated_argument( 'WP_Query', '3.1', __( '"caller_get_posts" is deprecated. Use "ignore_sticky_posts" instead.' ) ); 
     
    25912592                                $$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] : ''; 
    25922593                } 
    25932594 
     2595                if ( "$wpdb->posts.*" == $fields ) { 
     2596                        $fields = "$wpdb->posts.ID"; 
     2597                        $expand_ids = true;      
     2598                } 
     2599 
    25942600                if ( ! empty($groupby) ) 
    25952601                        $groupby = 'GROUP BY ' . $groupby; 
    25962602                if ( !empty( $orderby ) ) 
     
    26062612 
    26072613                if ( 'ids' == $q['fields'] ) { 
    26082614                        $this->posts = $wpdb->get_col($this->request); 
    2609  
    26102615                        return $this->posts; 
    2611                 } 
     2616                } elseif ( $expand_ids ) { 
     2617                        $ids = $wpdb->get_col( $this->request ); 
    26122618 
    2613                 if ( 'id=>parent' == $q['fields'] ) { 
     2619                        if ( $ids ) { 
     2620                                if ( !$q['no_found_rows'] && !empty( $limits ) ) { 
     2621                                        $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ); 
     2622                                        $this->found_posts = $wpdb->get_var( $found_posts_query ); 
     2623                                        $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) ); 
     2624                                        $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']); 
     2625                                } 
     2626         
     2627                                $query = sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s) $orderby", join( ",", $ids ) ); 
     2628                                $this->posts = $wpdb->get_results($query); 
     2629                        } else { 
     2630                                $this->found_posts = $this->max_num_pages = 0; 
     2631                                $this->posts = array(); 
     2632                        } 
     2633                } elseif ( 'id=>parent' == $q['fields'] ) { 
    26142634                        $this->posts = $wpdb->get_results($this->request); 
    26152635 
    26162636                        $r = array(); 
     
    26182638                                $r[ $post->ID ] = $post->post_parent; 
    26192639 
    26202640                        return $r; 
     2641                } else { 
     2642                        $this->posts = $wpdb->get_results($this->request); 
    26212643                } 
    26222644 
    2623                 $this->posts = $wpdb->get_results($this->request); 
    2624  
    26252645                // Raw results filter.  Prior to status checks. 
    26262646                if ( !$q['suppress_filters'] ) 
    26272647                        $this->posts = apply_filters_ref_array('posts_results', array( $this->posts, &$this ) ); 
     
    26392659                        $this->comment_count = count($this->comments); 
    26402660                } 
    26412661 
    2642                 if ( !$q['no_found_rows'] && !empty($limits) ) { 
     2662                if ( !$q['no_found_rows'] && !empty($limits) && !$expand_ids ) { 
    26432663                        $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ); 
    26442664                        $this->found_posts = $wpdb->get_var( $found_posts_query ); 
    26452665                        $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) );