Home › Forums › General Issues › Change user type field's return from array to ID, every CPT needs to be updated? › Reply To: Change user type field's return from array to ID, every CPT needs to be updated?
A user field always holds an array of user IDs. This might change if you only allow one user to be selected, but I don’t think so. You must still loop over the even when you are returning IDs.
$users = get_field('user_field_name');
// just in case it has a single value
if (!is_array('$users') && !emapty($users)) {
$users = array($users);
}
if ($users) {
foreach ($users as $user_id) {
// do something with user 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!
Make sure to register for tomorrow’s special ACF-focused edition of #BuildModeLive. Iain Poulson joins @hellosammunoz & @bgardner for a discussion about ACF’s roadmap and what’s in development. https://t.co/k93h4pYCae
— Advanced Custom Fields (@wp_acf) January 26, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.