Support

Account

Home Forums General Issues Update acf field with user emails

Solved

Update acf field with user emails

  • I have an ACF user field that I use to assign multiple users to a project and I need to pull there emails and put them into a list in another field, below is what I have so far and it partially works, it will pull one of the users emails and put it in the other field, but it wont pull all of them. Also, I need to have the list separated by commas.

    add_action('acf/save_post', 'my_acf_save_post');
    function my_acf_save_post($post_id){
        
        // get 'my_field' value
         $users = get_field('architect', $post_id);
    	foreach($users as $user){
        
        $user_emails = $user['user_email'];
    
    	}
        // update 'other_field' with 'my_field' value
        update_field('architect_notification', $user_emails, $post_id);
    	}
  • 
    add_action('acf/save_post', 'my_acf_save_post');
    function my_acf_save_post($post_id){
        
        // get 'my_field' value
         $users = get_field('architect', $post_id);
    
    // added
    $user_emails = array();
    
    	foreach($users as $user){
       
    // altered 
        $user_emails[] = $user['user_email'];
    
    	}
        // update 'other_field' with 'my_field' value
        update_field('architect_notification', $user_emails, $post_id);
    	}
    
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.