Changeset 31369
- Timestamp:
- 02/08/2015 04:58:14 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/user.php
r31269 r31369 501 501 * 502 502 * @since 3.1.0 503 * @since 4.2.0 Added 'meta_value_num' support for `$orderby` parameter. 503 504 * @access public 504 505 * … … 522 523 * 'nicename', 'email', 'url'. Default empty array. 523 524 * @type string $orderby Field to sort the retrieved users by. Accepts 'ID', 'display_name', 524 * 'login', 'nicename', 'email', 'url', 'registered', 'post_count', or 525 * 'meta_value'. To use 'meta_value', `$meta_key` must be also be defined. 525 * 'login', 'nicename', 'email', 'url', 'registered', 'post_count', 526 * 'meta_value' or 'meta_value_num'. To use 'meta_value' or 527 * 'meta_value_num', `$meta_key` must be also be defined. 526 528 * Default 'user_login'. 527 529 * @type string $order Designates ascending or descending order of users. Accepts 'ASC', … … 632 634 } elseif ( 'meta_value' == $qv['orderby'] ) { 633 635 $orderby = "$wpdb->usermeta.meta_value"; 636 } elseif ( 'meta_value_num' == $qv['orderby'] ) { 637 $orderby = "$wpdb->usermeta.meta_value+0"; 634 638 } elseif ( 'include' === $qv['orderby'] && ! empty( $include ) ) { 635 639 // Sanitized earlier. -
trunk/tests/phpunit/tests/user/query.php
r30094 r31369 131 131 132 132 $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] ); 133 157 134 158 $this->assertEquals( $expected, $q->get_results() );
Note: See TracChangeset
for help on using the changeset viewer.