Home › Forums › General Issues › 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);
You must be logged in to reply to this topic.
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.