Auto assign post object based on user’s email address
-
I’ve been running around and can’t figure this out for the life of me.
I have a custom post type called “Companies” where I create posts of each of my client company.I then have an ACF post object field in the User’s profile admin page that connects to the Companies CPT called user_company.
When an employee from said company registers for an account, I manually log in, go into their profile and select which company this person belongs to.
I’d like to do this automatically based on their email address.
This is what I have below but I’m not sure if I used update_field correctly or not since it’s not working. Only the user role is working.
add_action("um_user_register","um_042121_change_user_role", 10, 2 ); function um_042121_change_user_role( $user_id, $args ){ if( isset( $args['user_email'] ) ){ list($user, $domain) = explode('@', $args['user_email'] ); $user_company = get_field('user_company', 'user_' . $user_id); if ($domain == 'amyling.com') { wp_update_user( array( 'ID' => $user_id, 'role' => 'portal_member' ) ); update_field('user_company', '1725', 'user_' . $user_id); } } }
- The topic ‘Auto assign post object based on user’s email address’ is closed to new replies.