Home › Forums › ACF PRO › update_field and User Field Type › Reply To: update_field and User Field Type
Here is my optimized code if needed.
if ( (is_user_logged_in()) && ($_GET['action'] == 'follow') ) {
$user_followed_users = get_field('user_followed_users', 'user_'.$current_user->ID);
$user_followed_users_temp = array();
if (is_array($user_followed_users)) {
foreach($user_followed_users as $user) {
$user_followed_users_temp[] = $user['ID'];
}
if (!in_array($curauth->ID, $user_followed_users_temp)) {
$user_followed_users_temp[] = $curauth->ID;
} else {
// Clicking twice will remove the user form user followed list
if(($key = array_search($curauth->ID, $user_followed_users_temp)) !== false) {
unset($user_followed_users_temp[$key]);
}
}
} else {
$user_followed_users_temp = array($curauth->ID);
}
update_field('user_followed_users', $user_followed_users_temp, 'user_'.$current_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!
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.