WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/08/2015 04:58:14 PM (7 years ago)
Author:
boonebgorges
Message:

Add orderby=meta_value_num support to WP_User_Query.

Props tyxla, genkisan.
Fixes #27887.

File:
1 edited

Legend:

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

    r30094 r31369  
    131131
    132132        $expected = array( $users[1], $users[0], $users[2] );
     133
     134        $this->assertEquals( $expected, $q->get_results() );
     135    }
     136
     137    /**
     138     * @ticket 27887
     139     */
     140    public function test_orderby_meta_value_num() {
     141        $users = $this->factory->user->create_many( 3, array(
     142            'role' => 'author'
     143        ) );
     144
     145        update_user_meta( $users[0], 'user_age', '101' );
     146        update_user_meta( $users[1], 'user_age', '20' );
     147        update_user_meta( $users[2], 'user_age', '25' );
     148
     149        $q = new WP_User_Query( array(
     150            'include' => $users,
     151            'meta_key' => 'user_age',
     152            'orderby' => 'meta_value_num',
     153            'fields' => 'ids'
     154        ) );
     155
     156        $expected = array( $users[1], $users[2], $users[0] );
    133157
    134158        $this->assertEquals( $expected, $q->get_results() );
Note: See TracChangeset for help on using the changeset viewer.