Hello,
You can try to setup the student user into note post author field, for example:
1) Create a custom post type "notes",
2) Create a numeric post field "student-id", register it to post type "notes"
3) Create a custom user role "student"
4) Create a user view, query student user, output the student name and student ID as JSON format, use custom codes to remove all other HTML tags, here is the detail steps:
a) create a shortcode to hide the extra DIV tag from Views ouptut, add below codes into your theme/functions.php:
// remove extra HTML tags
add_shortcode('hide-it', 'hide_it_func');
function hide_it_func(){
return;
}
b) Create a user view "student-ids",query all student user, in views loop, output the student name and student ID as JSON format, and hide other HTMl tags:
[hide-it][wpv-layout-start][/hide-it]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-item index=1]{"value":"[wpv-user field="ID"]","label":"[wpv-user field="display_name"]"}
[wpv-item index=other],{"value":"[wpv-user field="ID"]","label":"[wpv-user field="display_name"]"}
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
[/wpv-no-items-found]
[hide-it][wpv-layout-end][/hide-it]
4) Create a post form for creating "notes" post, in the form content, display a general field, and use above view's shortcode to populate the field options, for example:
[cred_generic_field field='student-id' type='select' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":[],
"options":[ [wpv-view name="student-ids"] ]
}
[/cred_generic_field]
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_generic_field
5) Display above form in front-end, let teach users to create new "note" post, after submit this form, use below codes to update the post author as selected student
//update post author
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
// if a specific form - Form
if ($form_data['id']==12345) {
update_post_meta($post_id, 'wpcf-student-id', $_POST['student-id']);
}
}
Please replace 12345 with the post form ID of step 4)
6) In a single "note" post, you can get the "student-id" field value, use it to compare with current logged-in user's ID, then display the note information, for example:
[wpv-conditional if="'[types field='student-id' output='raw'][/types]' eq '[wpv-current-user info="id"]'"]
Display some information
[/wpv-conditional]
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-conditional