Skip to content

Instantly share code, notes, and snippets.

@tlehtimaki
Last active August 24, 2017 06:08
Show Gist options
  • Save tlehtimaki/c2d981b9135306038b84a8482de5e89f to your computer and use it in GitHub Desktop.
Save tlehtimaki/c2d981b9135306038b84a8482de5e89f to your computer and use it in GitHub Desktop.
Reordering WordPress User Table by User ID
<?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