Apps Ballance Cash_2 Chat Checkout Click Code Cog_Wheels Compose_email Conference Contacts Earth Edit_File_1_ Email Email_2 File Folder_2 Gift Group Group_2 Help ID ID_2 Key Keys Laptop_Store Like_1_ Link Lock Log_Out Map Marketing Mobile_UI Navigation POS Partnership Profile Safe_2 Search_User Secure_Files Settings Share Shield Shield_2 Shopping_Cart Support_Male Trash Type_pin User_female User_male logo copy

How to conditionally set a user role at registration using a custom field

Iain Poulson avatar
Iain Poulson Last updated on September 2, 2021

If you are using one registration form but want to register multiple types of users that will be given different roles on your site, then you might want to use a custom field which controls what role to give them. For example, you add a dropdown to your registration form and depending on what value they select, they get assigned a different role.


To get started, make sure the registration form is set to assign a default role for new users:

Then add a custom field you have created in Users > Custom Fields to the registration form, in my example I have a dropdown to capture the County they live in:
Find out they meta key of the field:

Then grab the code below and save to a wpum.php file to your /wp-content/mu-plugins/ directory (you might need to create the mu-plugins directory).

You will need to edit the meta field key to use your field, and also change the value logic so that the role is set to a different role if the field value is set as that value. You can then change the role as needed.

You can alter this logic to cater for fields that have multiple different options and different roles.

WP User Manager logo

Get Started with the Best WordPress Membership Plugin Today

Connect, Manage and Build your Membership Site

Need more help?

If you still didn't find an answer you can always contact us

Submit a ticket