Home › Forums › General Issues › Unable to write multiple values back to ACF user field › Reply To: Unable to write multiple values back to ACF user field
OK, I had thought of a couple ideas to try this morning, and things came together. Let me post my revised code. Essentially, I tried to follow the natural formatting to see if I could get everything to fall in line further along. I decided to convert the initial variable to an array, and that is what made everything else fall in line.
// get mentor & new mentee user arrays from the Match Metadata fields
$mentor = get_field(‘match_mentor’, $post_id);
$mentee = get_field(‘match_mentee’, $post_id);
//get ID from mentor array
$match_mentor_id = $mentor[‘ID’];
//get ID from mentee array
$match_mentee_id = $mentee[‘ID’];
//set up the mentor user_post_id
$mentor_post_id = “user_”.$match_mentor_id;
//get user array from mentor curent_users
$current_mentees = get_field(‘current_mentees’, $mentor_post_id, false);
// see if the current mentees is null or has a mentee already
if ($current_mentees == ”){
//put data in proper format
$current_mentees = array();
}
//combine old mentee(s) with new mentee
array_push( $current_mentees , $match_mentee_id);
//write new current mentees back to the Mentor User Meta fields
update_field(‘current_mentees’ , $current_mentees , $mentor_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.