WordPress: insert a custom post type instance as an option for a custom taxonomy

Ok, so I’m feeling generous and will add another answer 🙂

This code will run every time a post is created or updated, and it will add a term to your teacher taxonomy with a name that is the same as the post title.

add_action('save_post', 'my_create_teacher_term_from_post');
function my_project_updated_send_email($post_id){

    /** Ensure that this is not a revision */
    if(wp_is_post_revision($post_id))
        return;
    
    /** Get the name of the teacher that has been added/updated */
    $post_title = get_the_title(post_id);
    
    /** Check to see if a term with the same name as the teacher exists... */
    if(!term_exists($post_title, 'teacher')) :  // It does not...
    
        /** Insert the new term */
        wp_insert_term($post_title, 'teacher');
        
    endif;
    
}

Note – If you only want this action to occur when a post is created, not updated, replace the save_post hook with wp_insert_post.


Additional reading