Support Forum
Hi Long,
I need to autopopulate the relationship depending on the value of a post field. This is because when i upload the data, I can populate the user post field but I cannot populate the user relationship field. But I don't understand where I am going wrong with this code. My relationship is set from the post => User. And my aim is to assign the user to that post (university).
add_action( 'rwmb_frontend_after_process', function( $config, $post_id ) {
if ( 'academics_university' === $config['id'] ) { //'academics_university is the ID of a user meta field
$related_post_ids = empty( $_POST['university'] ) ? (array) $_post['academics_university'] : []; //'university' is the id of my CPT
foreach ( $related_post_ids as $related_post ) {
MB_Relationships_API::add( $post_id, $related_post_id, 'university_to_user' ); //this is the ID of the relationship university => user
}
}
}, 10, 2 );
What have I done wrong?
Also I think this is my last issue, then I promise I will leave you be, and no more questions.
Many thanks,
Yasmine