I want to sort users by User ID on users.php
by default. The page is currently ordered by username
as default.
Is there any hook to alter the order_by
option on users.php
?
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI want to sort users by User ID on users.php
by default. The page is currently ordered by username
as default.
Is there any hook to alter the order_by
option on users.php
?
You can use pre_get_users
since WP 4.0.0
function my_user_sort( $query_args ){
if( is_admin() && !isset($_GET['orderby']) ) {
$query_args->query_vars['orderby'] = 'ID';
}
return $query_args;
}
add_action( 'pre_get_users', 'my_user_sort' );
if( !isset($_GET['orderby']) ) {
. I didn't confirm whether pre_get_users
is called anywhere other than admin.
– BillK
Feb 7 '16 at 9:15
if( is_admin() && !isset($_GET['orderby']) )
condition is fine for me, since I only need this on admin. I think this is called anywhere, when the users query is called. Thanks for the answer.
– hkchakladar
Feb 7 '16 at 20:10