• Resolved xxaimsxx

    (@xxaimsxx)


    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);
        }
      }
    }
    • This topic was modified 2 years ago by xxaimsxx.
Viewing 1 replies (of 1 total)
  • Plugin Support ACF Support

    (@acfsupport)

    Hi there!

    ACF Support Team here. This forum is generally used by ACF users to help each other out.

    However, we would love to continue investigating and troubleshooting this issue, please can you create a ticket using our ?support form and we can look into it further.

Viewing 1 replies (of 1 total)
  • The topic ‘Auto assign post object based on user’s email address’ is closed to new replies.