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);
    	}
    
  • How could I modify the priority on this to get the new value right as it is updated? I have an email notification that is sent right when the architect_notification field is changed but it includes the old value and not the new value. Is this an issue with get_field?

  • your action might be firing before ACF saves values, try

    
    add_action('acf/save_post', 'my_acf_save_post', 20);
    
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.