Hi @tazar64
Are you sure you apply this in the right direction?
Based on the meta name it seems that you need to add the user to the course, not the course to the user, correct?
Cheers, Jory
Thank you for your response. Unfortunately, it does not work the other way around either. The code now is:
add_action(‘wpcw_enroll_student’, function($student_id, $course_ids) {
if (is_array($course_ids) && !empty($course_ids)) {
foreach ($course_ids as $course_id) {
$course_pod = pods(‘wpcw_course’, $course_id);
$course_pod->add_to(‘acces_user_exp-back’, $student_id);
}
}
}, 10, 2);
I have tested by updating other fields, and that worked fine. Could you please advise what might be wrong?
Hi @tazar64
I see you have also changed the field name. Could you share your field configurations? Or at least point out what field belongs to which Pod?
Cheers, Jory
The User extended POD has the relationship field: acces_user_exp and
wpcw_course POD has the bi-directional field: acces_user_exp-back
Hi @tazar64
I’ve checked the code and your initial config should work fine.
Though the add_to method also accepts a list of ID’s.
$user_pod->add_to( 'acces_user_exp', $course_ids );
Please make sure that the contents of $course_ids are in fact a list of ID’s, and not something else, like objects or an array of object vars.
Cheers, Jory