The reason for that is the save_post
loop. When you call wp_insert_post
, it triggers save_post
and thus inserts the student meta.
what you can do is, to check if the post type is correct while inserting the meta.
like:
add_action( 'save_post', 'save_student_meta', 10, 2 );
function save_student_meta( $post_id, $post ) {
if ( 'student' !== $post->post_type ) {
return;
}
// Code gathering data form $_POST