Home › Forums › General Issues › Multiple Select User Field and update_field() › Reply To: Multiple Select User Field and update_field()
My apologies, I knew in my wall of text I would omit things. That code in its entirety is actually –
$value = '21';
// format value
if( !$value || $value == 'null' )
{
return false;
}
// temp convert to array
$is_array = true;
if( !is_array($value) )
{
$is_array = false;
$value = array( $value );
}
foreach( $value as $k => $v )
{
$user_data = get_userdata( $v );
//cope with deleted users by @adampope
if( !is_object($user_data) )
{
unset( $value[$k] );
continue;
}
$value[ $k ] = array();
$value[ $k ]['ID'] = $v;
$value[ $k ]['user_firstname'] = $user_data->user_firstname;
$value[ $k ]['user_lastname'] = $user_data->user_lastname;
$value[ $k ]['nickname'] = $user_data->nickname;
$value[ $k ]['user_nicename'] = $user_data->user_nicename;
$value[ $k ]['display_name'] = $user_data->display_name;
$value[ $k ]['user_email'] = $user_data->user_email;
$value[ $k ]['user_url'] = $user_data->user_url;
$value[ $k ]['user_registered'] = $user_data->user_registered;
$value[ $k ]['user_description'] = $user_data->user_description;
$value[ $k ]['user_avatar'] = get_avatar( $v );
}
// de-convert from array
if( !$is_array && isset($value[0]) )
{
$value = $value[0];
}
Sorry about that.
So this was my code, but my issue from before still stands. I wouldn’t be able to output the array of $value and check the types using gettype as I previously mentioned if this was not the case.
I updated my original post to reflect this, so it’s not confusing to someone reading it for the first time. Thanks!
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.