Make WordPress Core

Changeset 15982


Ignore:
Timestamp:
10/26/2010 07:01:55 PM (16 years ago)
Author:
scribu
Message:

Introduce 'fields' query var to WP_Query. See #14777

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/query.php

    r15942 r15982  
    11801180                        , 's'
    11811181                        , 'sentence'
     1182                        , 'fields'
    11821183                );
    11831184
    11841185                foreach ( $keys as $key ) {
    1185                         if ( !isset($array[$key]))
     1186                        if ( !isset($array[$key]) )
    11861187                                $array[$key] = '';
    11871188                }
     
    11911192
    11921193                foreach ( $array_keys as $key ) {
    1193                         if ( !isset($array[$key]))
     1194                        if ( !isset($array[$key]) )
    11941195                                $array[$key] = array();
    11951196                }
     
    16411642                $search = '';
    16421643                $groupby = '';
    1643                 $fields = "$wpdb->posts.*";
     1644                $fields = '';
    16441645                $post_status_join = false;
    16451646                $page = 1;
     
    17211722                else
    17221723                        $q['no_found_rows'] = false;
     1724
     1725                switch ( $q['fields'] ) {
     1726                        case 'ids':
     1727                                $fields = "$wpdb->posts.ID";
     1728                                break;
     1729                        case 'id=>parent':
     1730                                $fields = "$wpdb->posts.ID, $wpdb->posts.post_parent";
     1731                                break;
     1732                        default:
     1733                                $fields = "$wpdb->posts.*";
     1734                }
    17231735
    17241736                // If a month is specified in the querystring, load that month
     
    22582270                if ( !empty( $orderby ) )
    22592271                        $orderby = 'ORDER BY ' . $orderby;
     2272
    22602273                $found_rows = '';
    22612274                if ( !$q['no_found_rows'] && !empty($limits) )
     
    22662279                        $this->request = apply_filters_ref_array('posts_request', array( $this->request, &$this ) );
    22672280
     2281                if ( 'ids' == $q['fields'] ) {
     2282                        $this->posts = $wpdb->get_col($this->request);
     2283
     2284                        return $this->posts;
     2285                }
     2286
     2287                if ( 'id=>parent' == $q['fields'] ) {
     2288                        $this->posts = $wpdb->get_results($this->request);
     2289
     2290                        $r = array();
     2291                        foreach ( $this->posts as $post )
     2292                                $r[ $post->ID ] = $post->post_parent;
     2293
     2294                        return $r;
     2295                }
     2296
    22682297                $this->posts = $wpdb->get_results($this->request);
     2298
    22692299                // Raw results filter.  Prior to status checks.
    22702300                if ( !$q['suppress_filters'] )
Note: See TracChangeset for help on using the changeset viewer.