Make WordPress Core

Ticket #43636: wp_query_fields.diff

File wp_query_fields.diff, 1.8 KB (added by mattkeys, 7 years ago)

Patch for the proposed enhancement

  • class-wp-query.php

     
    18551855                        case 'id=>parent':
    18561856                                $fields = "{$wpdb->posts}.ID, {$wpdb->posts}.post_parent";
    18571857                                break;
     1858                        case 'author_ids':
     1859                                $fields = "{$wpdb->posts}.ID, {$wpdb->posts}.post_author";
     1860                                break;
     1861                        case 'titles':
     1862                                $fields = "{$wpdb->posts}.ID, {$wpdb->posts}.post_title";
     1863                                break;
    18581864                        default:
    18591865                                $fields = "{$wpdb->posts}.*";
    18601866                }
     
    29072913                        return $r;
    29082914                }
    29092915
     2916                if ( 'author_ids' == $q['fields'] ) {
     2917                        if ( null === $this->posts ) {
     2918                                $this->posts = $wpdb->get_results( $this->request );
     2919                        }
     2920
     2921                        $this->post_count = count( $this->posts );
     2922                        $this->set_found_posts( $q, $limits );
     2923
     2924                        $r = array();
     2925                        foreach ( $this->posts as $key => $post ) {
     2926                                $this->posts[ $key ]->ID = (int) $post->ID;
     2927                                $this->posts[ $key ]->post_author = (int) $post->post_author;
     2928
     2929                                $r[ (int) $post->ID ] = (int) $post->post_author;
     2930                        }
     2931
     2932                        return $r;
     2933                }
     2934
     2935                if ( 'titles' == $q['fields'] ) {
     2936                        if ( null === $this->posts ) {
     2937                                $this->posts = $wpdb->get_results( $this->request );
     2938                        }
     2939
     2940                        $this->post_count = count( $this->posts );
     2941                        $this->set_found_posts( $q, $limits );
     2942
     2943                        $r = array();
     2944                        foreach ( $this->posts as $key => $post ) {
     2945                                $this->posts[ $key ]->ID = (int) $post->ID;
     2946                                $this->posts[ $key ]->post_title = sanitize_text_field( $post->post_title );
     2947
     2948                                $r[ (int) $post->ID ] = sanitize_text_field( $post->post_title );
     2949                        }
     2950
     2951                        return $r;
     2952                }
     2953
    29102954                if ( null === $this->posts ) {
    29112955                        $split_the_query = ( $old_request == $this->request && "{$wpdb->posts}.*" == $fields && ! empty( $limits ) && $q['posts_per_page'] < 500 );
    29122956