Home › Forums › General Issues › How to update (add to) a user field via php › Reply To: How to update (add to) a user field via php
The user field holds an array of user IDs.
If you want to add a user ID to the field that already has values.
// get the user field without formatting
$users = get_field('user_field', $post_id, false);
// test to see if empty
if (empty($users)) {
$users = array();
}
// add a user
$users[] = $new_user_id;
// use field key to update field
// it will not update using field name
// if it did not already have a value
update_field('field_XXXXXXX', $users, $post_id);
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.