First off I found this question: generate unique number when registering a user

which is almost exactly what I need except I need the number generated to be auto incremented instead of random. I'd like the first number to be a 4 digit number then auto incremented from there. Ideally it would never get longer than say 6 digits and then would replace the first digit with a letter but maybe thats not possible?

The number needs to be displayed and searchable from the user list in the admin area

//create unique id for decal on new user creation
add_action( 'user_register', 'my_on_user_register' );
function my_on_user_register( $user_id ) {
    $unique_id = 1000 + $user_id;
    update_user_meta( $user_id, 'my_unique_id', $unique_id );
//display decal code on profile
add_action('show_user_profile', 'my_extra_user_profile_fields');
add_action('edit_user_profile', 'my_extra_user_profile_fields');
function my_extra_user_profile_fields($user){

    $unique_number = get_the_author_meta('my_unique_id', $user->ID);
    <h3><?php _e('Decal Info'); ?></h3>

    <table class="form-table">
            <th><label for="address"><?php _e('Code:'); ?></label></th>
            <td><?php echo $unique_number; ?></td>
//send email with decal code to admin on new user
function registration_email_alert($user_id) {
    $message = strip_tags($_POST['user_login']). ' - ' . strip_tags($_POST['user_email']) . ' Decal Code: ' . strip_tags($user_id['my_unique_id']) . ' Has Registered To Your Website';
    wp_mail( '[email protected]', 'New Teen Has Been Registered', $message );
add_action('user_register', 'registration_email_alert');
//add decal code to user list
function new_modify_user_table( $column ) {
    $column['my_unique_id'] = 'Decal Code';
    return $column;
add_filter( 'manage_users_columns', 'new_modify_user_table' );

function new_modify_user_table_row( $val, $column_name, $user_id ) {
    $user = get_userdata( $user_id );
    switch ($column_name) {
        case 'my_unique_id' :
            return get_the_author_meta( 'my_unique_id', $user_id );
    return $return;
add_filter( 'manage_users_custom_column', 'new_modify_user_table_row', 10, 3 );

1 Answer 1


You can use the same method as described in the link you mentioned, but simply use the created user ID and add 1000 so you get four digits. So user_id = 5 gets the meta number of 1005.

add_action( 'user_register', 'my_on_user_register' );
function my_on_user_register( $user_id ) {
    $unique_id = 1000 + $user_id;
    update_user_meta( $user_id, 'my_unique_id', $unique_id );

Hope that helps!

  • worked a trick thanks. I also added the field to the profile page and to the user list. But any ideas how to make it searchable in the user list? adding my full code to original question
    – mcmasterp
    May 7, 2015 at 23:57

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.