我的项目是与领养导师和;学员用户。然后再向导师添加其他学员。
我的导师有一个ACF current\\u mentees(用户列表)字段。我可以添加一个用户。但当我尝试推/添加另一个时,它无法正确添加第二个。
// 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 & mentee array
$match_mentor_id = $mentor[\'ID\'];
$match_mentee_id = $mentee[\'ID\'];
//set up the mentor user_post_id
$mentor_post_id = "user_".$match_mentor_id;
//get mentor curent_users contents
$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 == \'\'){
//write new mentee back to the Mentor User Meta field
update_field(\'current_mentees\' , $match_mentee_id , $mentor_post_id);
} else {
//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);
}
match\\u导师;match\\u mentees和current\\u mentees都是ACF字段。我可以通过用户帐户中的下拉列表将(学员)用户(单个和多个)手动添加到当前的\\u学员。它显示为数组的数组。第一个看起来像:a:1:{i:0;s:2:“60〃;}//用户60添加第二个会得到:a:2:{i:0;s:2:“60”;i:1;s:2:“57;”//用户60及;57这对我来说是有用的。我希望代码也能这样做。但是使用上述代码添加一个用户,在current\\u mentees字段/DB中,我看到了60。然后加上第二个,我得到a:1:{I:0;I:57;}。(它将替换第一个用户,而不是添加第二个用户)。
我不确定这是否是开始错误的(对于第一个用户),或者是否需要在添加第二个变量之前修改变量(我已经尝试过)。谢谢