Support

Account

Home Forums ACF PRO Conditional display of a custom taxonomy based according to user (when posting) Reply To: Conditional display of a custom taxonomy based according to user (when posting)

  • This may be complicated to explain but i’ll give it my best shot.

    The background…

    I’m making a site whereby teachers from different schools can create posts about different students from different schools. Importantly, teachers may only be able to view/choose/check/tick students from the same school as themselves.

    I have created new user roles (and capabilities) for teachers according to the name of their school e.g.
    XYZ primary school teachers are assigned the user role: xyz and capability: xyz
    ABC highschool teachers are assigned the user role: abc and capability: abc

    I have ACF Pro and CPTUI plugin to create new custom taxonomies.

    I have created a taxonomy student that contains the names of all the students.

    I have created a taxonomy school that contains the names of the different schools.

    WIth ACF I have created a field group that assigns the school taxonomy to the student taxonomy. This means when I create or edit an individual student term the student has a school taxonomy radio button for me to choose which school the student is assigned/belongs to.

    I have also done the same to the users (teachers). I have created a field group that assigns the school taxonomy to the users. This means when I create or edit a user (teacher) the user has a school taxonomy radio button for me to choose which user the user/teacher is assigned/belongs to.

    As you can see the above field groups that assign the school taxonomy to the users and student taxonomy gives both the users/teachers and students a common link/taxonomy (school).

    I have created another field group assigned to a post with many other fields.

    This is where my question really starts….

    When a user/teacher creates a post one of the fields the user must tick is the student. However, all the student names are listed. I only want the students(terms) assigned with the same school taxonomy as the user creating the post to be visible in the list of students. In other words only populate the student taxonomy with those students(terms) that have the same school(term) as the user(teacher) creating the post.

    When creating or editing a post…

    IF current_user (has_term(XYZ) in_tax(school))
    THEN populate taxonomy(student) with (has_term(XYZ) in_tax(school))
    Another way may be to have a condition whereby…

    IF current_user (user_capability(xyz)
    THEN populate taxonomy(student) with (has_term(XYZ) in_tax(school))
    Either way is fine by me the important thing is to only display the student names that belong to the same school as the teachers creating the post.