Created
February 3, 2015 12:53
-
-
Save technoknol/34030628b7b2e71c26a0 to your computer and use it in GitHub Desktop.
Patch : WP_User_Query orderby meta_value_num
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Paste this code in functions.php of your active theme. | |
add_action( 'pre_user_query', 'wps_pre_user_query' ); | |
function wps_pre_user_query( &$query ) { | |
global $wpdb; | |
if ( isset( $query->query_vars['orderby'] ) && 'meta_value_num' == $query->query_vars['orderby'] ) | |
$query->query_orderby = str_replace( 'user_login', "$wpdb->usermeta.meta_value+0", $query->query_orderby ); | |
} | |
// Usage :: | |
$args['order'] = 'ASC'; | |
$args['orderby'] = 'meta_value_num' ; | |
$args['meta_key'] = 'users_numeric_meta_value' ; | |
$user_query = new WP_User_Query( $args ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment