Home › Forums › General Issues › Add additional role to user › Reply To: Add additional role to user
Thanks John worked it out from your input.
Here’s the code if anyone else needs help as I looked around for quite a while before raising a ticket.
add_action (‘acf/save_post’, ‘add_role_on_selection’);
function add_role_on_selection ($post_id) {
// Get newly saved values.
$values = get_fields( $post_id );
// Check the new value of a specific field.
$selected = get_field(‘stall_catergory’, $post_id);
$user = wp_get_current_user();
if( $selected == ‘general’) {
$user->add_role(‘general’);
}
if( $selected == ‘food’) {
$user->add_role(‘food’);
}
if( $selected == ‘hot food’) {
$user->add_role(‘hot_food’);
}
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.