Make WordPress Core

Ticket #35476: 35476.diff

File 35476.diff, 2.6 KB (added by adamsilverstein, 10 years ago)
  • src/wp-includes/query.php

     
    35313531                }
    35323532
    35333533                if ( 'ids' == $q['fields'] ) {
    3534                         $this->posts = $wpdb->get_col( $this->request );
    3535                         $this->posts = array_map( 'intval', $this->posts );
    3536                         $this->post_count = count( $this->posts );
    3537                         $this->set_found_posts( $q, $limits );
    35383534
     3535                        /**
     3536                         * Filter the query results when 'fields' specified in a query.
     3537                         *
     3538                         * Plugins can bypass a 'fields' query by returning
     3539                         * an array of posts to be returned from the query.
     3540                         *
     3541                         * @since 4.5.0
     3542                         *
     3543                         * @param array    $posts   The filtered array of posts.
     3544                         * @param array    $request The complete SQL query.
     3545                         * @param string   $fields  The query 'fields' value.
     3546                         * @param WP_Query &$this   The WP_Query instance (passed by reference).
     3547                         */
     3548                        $this->posts = apply_filters_ref_array( 'fields_the_posts', array( false, $q['fields'], $this->request, &$this ) );
     3549
     3550                        if ( false === $this->posts ) {
     3551                                $this->posts = $wpdb->get_col( $this->request );
     3552                                $this->posts = array_map( 'intval', $this->posts );
     3553                                $this->post_count = count( $this->posts );
     3554                                $this->set_found_posts( $q, $limits );
     3555                        }
     3556
    35393557                        return $this->posts;
    35403558                }
    35413559
    35423560                if ( 'id=>parent' == $q['fields'] ) {
    3543                         $this->posts = $wpdb->get_results( $this->request );
    3544                         $this->post_count = count( $this->posts );
    3545                         $this->set_found_posts( $q, $limits );
     3561                        /** This filter is documented in wp-includes/query.php */
     3562                        $this->posts = apply_filters_ref_array( 'fields_the_posts', array( false, $q['fields'], $this->request, &$this ) );
    35463563
    3547                         $r = array();
    3548                         foreach ( $this->posts as $key => $post ) {
    3549                                 $this->posts[ $key ]->ID = (int) $post->ID;
    3550                                 $this->posts[ $key ]->post_parent = (int) $post->post_parent;
     3564                        if ( false === $this->posts ) {
     3565                                $this->posts = $wpdb->get_results( $this->request );
     3566                                $this->post_count = count( $this->posts );
     3567                                $this->set_found_posts( $q, $limits );
    35513568
    3552                                 $r[ (int) $post->ID ] = (int) $post->post_parent;
     3569                                $r = array();
     3570                                foreach ( $this->posts as $key => $post ) {
     3571                                        $this->posts[ $key ]->ID = (int) $post->ID;
     3572                                        $this->posts[ $key ]->post_parent = (int) $post->post_parent;
     3573
     3574                                        $r[ (int) $post->ID ] = (int) $post->post_parent;
     3575                                }
     3576
     3577                                $this->posts = $r;
    35533578                        }
    35543579
    3555                         return $r;
     3580                        return $this->posts;
    35563581                }
    35573582
    35583583                $split_the_query = ( $old_request == $this->request && "$wpdb->posts.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 );