Make WordPress Core

Changeset 31324


Ignore:
Timestamp:
02/03/2015 02:28:52 AM (12 years ago)
Author:
SergeyBiryukov
Message:

When using WP_Query's 'fields' => 'ids' (or 'fields' => 'id=>parent'), make sure the returned result is always an array of integers.

fixes #31194. see #27252.

Location:
trunk
Files:
2 edited

Legend:

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

    r31321 r31324  
    34223422                if ( 'ids' == $q['fields'] ) {
    34233423                        $this->posts = $wpdb->get_col( $this->request );
     3424                        $this->posts = array_map( 'intval', $this->posts );
    34243425                        $this->post_count = count( $this->posts );
    34253426                        $this->set_found_posts( $q, $limits );
    34263427
    3427                         return array_map( 'intval', $this->posts );
     3428                        return $this->posts;
    34283429                }
    34293430
    … …  
    34343435
    34353436                        $r = array();
    3436                         foreach ( $this->posts as $post ) {
     3437                        foreach ( $this->posts as $key => $post ) {
     3438                                $this->posts[ $key ]->ID = (int) $post->ID;
     3439                                $this->posts[ $key ]->post_parent = (int) $post->post_parent;
     3440
    34373441                                $r[ (int) $post->ID ] = (int) $post->post_parent;
    34383442                        }
     3443
    34393444                        return $r;
    34403445                }
  • trunk/tests/phpunit/tests/query/results.php

    r30524 r31324  
    388388        /**
    389389         * @ticket 27252
     390         * @ticket 31194
    390391         */
    391392        function test_query_fields_integers() {
    … …  
    402403
    403404                $this->assertSame( $parents, $posts1 );
     405                $this->assertSame( $parents, $this->q->posts );
    404406
    405407                $children = array(
    … …  
    415417
    416418                $this->assertSame( $children, $posts2 );
     419
     420                foreach ( $this->q->posts as $post ) {
     421                        $this->assertInternalType( 'int', $post->ID );
     422                        $this->assertInternalType( 'int', $post->post_parent );
     423                }
    417424
    418425        }
Note: See TracChangeset for help on using the changeset viewer.