WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to generate a unique ID number for each new member. I was going to use WP_query, but am not getting anything but an array.

share|improve this question
I am unsure what you are trying to achieve. Are you trying to generate a user ID or are you trying to display the user ID? If you are generating a new user ID why not just use the one WP assigns? – imHavoc Dec 10 '11 at 4:51
That's what I will probably do, I just don't know how to add it to a members information, ie. username, email, ID – jerry Dec 18 '11 at 6:16
I am still unsure of what you want to do, but it seems that you want to add information to a user. Can you please be more specific? – imHavoc Dec 18 '11 at 18:43
I want to grab the user id, and have it print out with the rest of the user profile stuff. – jerry Jan 3 '12 at 22:52

If you want to display the info on the current user logged in you can use get_currentuserinfo. [Codex]

Example from Codex

<?php global $current_user;

      echo 'Username: ' . $current_user->user_login . "\n";
      echo 'User email: ' . $current_user->user_email . "\n";
      echo 'User first name: ' . $current_user->user_firstname . "\n";
      echo 'User last name: ' . $current_user->user_lastname . "\n";
      echo 'User display name: ' . $current_user->display_name . "\n";
      echo 'User ID: ' . $current_user->ID . "\n";

Or if you want display the info for a user that is not the current user logged in, you can use get_userdata. [Codex]

The two links to the WP Codex should provide you with the syntax of the two functions. If you have any further questions or they did not work please ask.

share|improve this answer
Thanks! Hey, just a quick question, would you say this is the best way to create a unique number for a member? I was going to use rand(1,0000000) but it is random, and keeps changing. I came to the conclusion that the user ID is really the best way to make sure each users number is unique. Sound safe? – jerry Jan 5 '12 at 18:29
The User ID will always be unique because it auto increments in the database and the column is set to unique, so you should be fine. – imHavoc Jan 5 '12 at 18:59
How can I do this? I cannot seem to get it to echo out in each members profile area? – jerry Jan 5 '12 at 23:22
What is the code you are using? – imHavoc Jan 6 '12 at 1:36
' <?php $user_number = get_userdata( $userid ); ?> <span>My User Number is: <?php echo $user_number; ?> <br /> ' – jerry Jan 6 '12 at 16:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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