WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/10/2013 11:09:10 PM (7 years ago)
Author:
wonderboymusic
Message:

Support orderby => meta_value in WP_User_Query. Adds unit test.

Props wpsmith.
Fixes #21581.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/user/query.php

    r25002 r25331  
    7777        }
    7878    }
     79
     80    function test_orderby() {
     81        $user_ids = $this->factory->user->create_many( 10, array(
     82            'role' => 'author'
     83        ) );
     84
     85        $names = array( 'd', 'f', 'n', 'f', 'd', 'j', 'r', 'p', 'h', 'g' );
     86
     87        foreach ( $names as $i => $name )
     88            update_user_meta( $user_ids[$i], 'last_name', $name );
     89
     90        $u = new WP_User_Query( array(
     91            'include' => $user_ids,
     92            'meta_key' => 'last_name',
     93            'orderby' => 'meta_value',
     94            'fields' => 'ids'
     95        ) );
     96        $values = array();
     97        foreach ( $u->get_results() as $user )
     98            $values[] = get_user_meta( $user, 'last_name', true );
     99
     100        sort( $names );
     101
     102        $this->assertEquals( $names, $values );
     103    }
    79104}
Note: See TracChangeset for help on using the changeset viewer.