Make WordPress Core

Ticket #35476: fields-the-posts.diff

File fields-the-posts.diff, 2.0 KB (added by tlovett1, 10 years ago)

Add fields_the_posts filters

  • 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 );
     3534                        $this->posts = apply_filters( 'fields_the_posts', false, $q['fields'], $this->request, &$this );
    35383535
     3536                        if ( false === $this->posts ) {
     3537                                $this->posts = $wpdb->get_col( $this->request );
     3538                                $this->posts = array_map( 'intval', $this->posts );
     3539                                $this->post_count = count( $this->posts );
     3540                                $this->set_found_posts( $q, $limits );
     3541                        }
     3542
    35393543                        return $this->posts;
    35403544                }
    35413545
    35423546                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 );
     3547                        $this->posts = apply_filters( 'fields_the_posts', false, $q['fields'], $this->request, &$this );
    35463548
    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;
     3549                        if ( false === $this->posts ) {
     3550                                $this->posts = $wpdb->get_results( $this->request );
     3551                                $this->post_count = count( $this->posts );
     3552                                $this->set_found_posts( $q, $limits );
    35513553
    3552                                 $r[ (int) $post->ID ] = (int) $post->post_parent;
     3554                                $r = array();
     3555                                foreach ( $this->posts as $key => $post ) {
     3556                                        $this->posts[ $key ]->ID = (int) $post->ID;
     3557                                        $this->posts[ $key ]->post_parent = (int) $post->post_parent;
     3558
     3559                                        $r[ (int) $post->ID ] = (int) $post->post_parent;
     3560                                }
     3561
     3562                                $this->posts = $r;
    35533563                        }
    35543564
    3555                         return $r;
     3565                        return $this->posts;
    35563566                }
    35573567
    35583568                $split_the_query = ( $old_request == $this->request && "$wpdb->posts.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 );