Thanks for writing back.
Yes, this is possible using a custom function attached to the "cred_save_data" hook, for the form to add a new post:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
You'll need the ID of the teacher post from the currently logged-in user. For this, you can register a custom shortcode. The following code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
add_shortcode('current_teacher_id', 'current_teacher_id_func');
function current_teacher_id_func( $atts ) {
$a = shortcode_atts( array(
'type' => '',
), $atts );
$user_post = get_posts( array(
'post_type' => $a['type'],
'author' => get_current_user_id(),
'numberposts' => 1
) );
if(!empty($user_post)) {
return $user_post[0]->ID;
}
else{
return 0;
}
}
Next, please add "current_teacher_id" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.
After that, you'll be able to use this shortcode like this, to get the currently logged-in user's teacher post:
[current_teacher_id type="teacher-post-slug"]
Note: you'll replace "teacher-post-slug", with the actual slug of your teacher post type.
In the form to add a new school, you can include a hidden generic field and prefill the currently logged-in teacher's post ID, using this new shortcode.
As a result, in your custom function attached to the "cred_save_data" hook, you'll have the ID of the newly created school's post as well as the current user's teacher's post and you can create a relationship between them using the "toolset_connect_posts" function:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts
When the form submission will complete, the new school will be added and the current teacher's post will also be linked to that school.