Make WordPress Core

Changeset 26307


Ignore:
Timestamp:
11/21/2013 07:30:35 PM (11 years ago)
Author:
wonderboymusic
Message:

In update_meta_cache(), ensure that meta is always stored in the same order. Removes an unnecessary $wpdb->prepare statement. Adds unit test.

Props mattheu.
Fixes #25511.

Location:
trunk
Files:
2 edited

Legend:

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

    r26055 r26307  
    559559
    560560    // Get meta info
    561     $id_list = join(',', $ids);
    562     $meta_list = $wpdb->get_results( $wpdb->prepare("SELECT $column, meta_key, meta_value FROM $table WHERE $column IN ($id_list)",
    563         $meta_type), ARRAY_A );
     561    $id_list = join( ',', $ids );
     562    $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id';
     563    $meta_list = $wpdb->get_results( "SELECT $column, meta_key, meta_value FROM $table WHERE $column IN ($id_list) ORDER BY $id_column ASC", ARRAY_A );
    564564
    565565    if ( !empty($meta_list) ) {
  • trunk/tests/phpunit/tests/meta.php

    r25255 r26307  
    172172        $this->assertEquals( 2, substr_count( $posts->request, 'CAST(' ) );
    173173    }
     174
     175    function test_meta_cache_order_asc() {
     176        $post_id = $this->factory->post->create();
     177        $colors = array( 'red', 'blue', 'yellow', 'green' );
     178        foreach ( $colors as $color )
     179            add_post_meta( $post_id, 'color', $color );
     180
     181        foreach ( range( 1, 10 ) as $i ) {
     182            $meta = get_post_meta( $post_id, 'color' );
     183            $this->assertEquals( $meta, $colors );
     184
     185            if ( 0 === $i % 2 )
     186                wp_cache_delete( $post_id, 'post_meta' );
     187        }
     188    }
    174189}
Note: See TracChangeset for help on using the changeset viewer.