Last active
August 24, 2017 06:08
-
-
Save tlehtimaki/c2d981b9135306038b84a8482de5e89f to your computer and use it in GitHub Desktop.
Reordering WordPress User Table by User ID
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 | |
/** | |
* Reorder WordPress User table by user ID | |
* | |
* @param object $query Instance of WP_User_Query | |
* @return object $query Altered instance of WP_User_Query | |
*/ | |
function my_custom_order_users_by_id( $query ) { | |
// Check that we are in admin otherwise return | |
if( ¡ is_admin() ) { | |
return | |
} | |
// We are changing the query_vars to reorder | |
$query->query_vars['orderby'] = 'ID'; | |
$query->query_vars['order'] = 'DESC'; | |
// We need to remember to return the altered query. | |
return $query; | |
} | |
// Lets apply our function to hook. | |
add_action( 'pre_get_users', 'my_custom_order_users_by_id' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment