3

I have tried to get the recently registered author user ID. i have no code now, because the below code can't use role to filter it.

SELECT max(ID) FROM $wpdb->users LIMIT 1

and get_usersfunction can get list of the users.

not sure.how to obtain results.

1
  • By registered date! Most recent date should belong to last added user!
    – Sumit
    Commented Mar 15, 2016 at 17:26

1 Answer 1

7

I don't think you need any SQL queries.

<?php

$args = array(
    'role'         => 'author', // authors only
    'orderby'      => 'registered', // registered date
    'order'        => 'DESC', // last registered goes first
    'number'       => 1 // limit to the last one, not required
);

$users = get_users( $args );

$last_user_registered = $users[0]; // the first user from the list

echo $last_user_registered->ID; // print user ID

Here you can find complete information on how to use get_users() function.

1
  • 1
    I am bit late, I was just typing same :P
    – Sumit
    Commented Mar 15, 2016 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.