User to User n:n relationship based on User role
Support › MB Relationships › User to User n:n relationship based on User roleResolved
- This topic has 2 replies, 3 voices, and was last updated 4 years ago by
Omni.
-
AuthorPosts
-
October 31, 2018 at 6:06 PM #11799
aristo
ParticipantHello Anh,
So I'm trying to create a relationship between users as mentioned on this MB relationship plugin "Supports creating reciprocal relationships (posts-posts, users-users, …)." based on their roles.
let's say there is a "student" and "teacher". I want to create a reciprocal relationship between them, saying "student" can choose "teacher" and vice-versa. with a single field.
For now, I tried this code.
add_action( 'mb_relationships_init', function () { MB_Relationships_API::register( array( 'id' => 'stud_to_teach', 'from' => array( 'object_type' => 'user', 'role__in' => 'student', 'meta_box' => array( 'title' => 'Manages', 'field_title' => 'Select Users', ), ), 'to' => array( 'object_type' => 'user', 'user_role' => 'teacher', 'meta_box' => array( 'title' => 'Manages users', 'field_title' => 'Select Users', ), ), ) ); } );what it's doing is creating 2 fields. and allowing me to add more, but it's showing every type of users. am I using the key
user_rolewrong? what should be the correct key?also I'm struggling with the logic of
if logged_in_user is student then show only teacher. And if logged_in_user is teacher then show only student.
October 31, 2018 at 10:55 PM #11809Anh Tran
KeymasterHi Aristo,
You need to put the user role inside
query_args, like this:add_action( 'mb_relationships_init', function () { MB_Relationships_API::register( array( 'id' => 'stud_to_teach', 'from' => array( 'object_type' => 'user', 'query_args' => array( 'role__in' => 'student' ), 'meta_box' => array( 'title' => 'Manages', 'field_title' => 'Select Users', ), ), 'to' => array( 'object_type' => 'user', 'query_args' => array( 'role__in' => 'teacher' ), 'meta_box' => array( 'title' => 'Manages users', 'field_title' => 'Select Users', ), ), ) ); } );November 11, 2021 at 12:31 AM #31855Omni
ParticipantThis doesn't seem to work.. is there an update?
-
AuthorPosts
- You must be logged in to reply to this topic.