Add `orderby=meta_value_num` support to `WP_User_Query`.
Props tyxla, genkisan. Fixes #27887. Built from https://develop.svn.wordpress.org/trunk@31369 git-svn-id: http://core.svn.wordpress.org/trunk@31350 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
623981c8d6
commit
17330354bc
|
@ -500,6 +500,7 @@ class WP_User_Query {
|
||||||
* Prepare the query variables.
|
* Prepare the query variables.
|
||||||
*
|
*
|
||||||
* @since 3.1.0
|
* @since 3.1.0
|
||||||
|
* @since 4.2.0 Added 'meta_value_num' support for `$orderby` parameter.
|
||||||
* @access public
|
* @access public
|
||||||
*
|
*
|
||||||
* @param string|array $query {
|
* @param string|array $query {
|
||||||
|
@ -521,8 +522,9 @@ class WP_User_Query {
|
||||||
* @type array $search_columns Array of column names to be searched. Accepts 'ID', 'login',
|
* @type array $search_columns Array of column names to be searched. Accepts 'ID', 'login',
|
||||||
* 'nicename', 'email', 'url'. Default empty array.
|
* 'nicename', 'email', 'url'. Default empty array.
|
||||||
* @type string $orderby Field to sort the retrieved users by. Accepts 'ID', 'display_name',
|
* @type string $orderby Field to sort the retrieved users by. Accepts 'ID', 'display_name',
|
||||||
* 'login', 'nicename', 'email', 'url', 'registered', 'post_count', or
|
* 'login', 'nicename', 'email', 'url', 'registered', 'post_count',
|
||||||
* 'meta_value'. To use 'meta_value', `$meta_key` must be also be defined.
|
* 'meta_value' or 'meta_value_num'. To use 'meta_value' or
|
||||||
|
* 'meta_value_num', `$meta_key` must be also be defined.
|
||||||
* Default 'user_login'.
|
* Default 'user_login'.
|
||||||
* @type string $order Designates ascending or descending order of users. Accepts 'ASC',
|
* @type string $order Designates ascending or descending order of users. Accepts 'ASC',
|
||||||
* 'DESC'. Default 'ASC'.
|
* 'DESC'. Default 'ASC'.
|
||||||
|
@ -631,6 +633,8 @@ class WP_User_Query {
|
||||||
$orderby = 'ID';
|
$orderby = 'ID';
|
||||||
} elseif ( 'meta_value' == $qv['orderby'] ) {
|
} elseif ( 'meta_value' == $qv['orderby'] ) {
|
||||||
$orderby = "$wpdb->usermeta.meta_value";
|
$orderby = "$wpdb->usermeta.meta_value";
|
||||||
|
} elseif ( 'meta_value_num' == $qv['orderby'] ) {
|
||||||
|
$orderby = "$wpdb->usermeta.meta_value+0";
|
||||||
} elseif ( 'include' === $qv['orderby'] && ! empty( $include ) ) {
|
} elseif ( 'include' === $qv['orderby'] && ! empty( $include ) ) {
|
||||||
// Sanitized earlier.
|
// Sanitized earlier.
|
||||||
$include_sql = implode( ',', $include );
|
$include_sql = implode( ',', $include );
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.2-alpha-31368';
|
$wp_version = '4.2-alpha-31369';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue