'Save custom meta box too while inserting post from frontend wordpress

$student = array(
            'post_title' => wp_strip_all_tags( $student_name ),
            'post_status' => 'private', 
            'post_type' => 'student'  
        );

        wp_insert_post($student);

This is how I'm inserting post from the frontend. it is working fine. But I need to save some custom fields also from frontend along with post and need show the values in backend(just in text format not in input field). So is there anything exists like this 'my_custom_filed' => 'custom_value':

$student = array(
            'post_title' => wp_strip_all_tags( $student_name ),
             'my_custom_filed' => 'custom_value'
            'post_status' => 'private', 
            'post_type' => 'student' 
           
        );

        wp_insert_post($student);

So I can print the value of custom fields in backend

 function studentDataMetaBoxStructure(){
        global $post;
        $my_custom_filed = get_post_meta($post->ID,'my_custom_filed',true);

        echo $my_custom_filed;

    }

But I'm getting nothing in $my_custom_filed;



Solution 1:[1]

This is how you save meta box while post insertion.

 $student = array(
                    'post_title' => wp_strip_all_tags( $student_name ),
                     'my_custom_filed' => 'custom_value'
                    'post_status' => 'private', 
                    'post_type' => 'student' 
                   
                );
        
               $the_post_id =  wp_insert_post($student);
               update_post_meta( $the_post_id, 'custom_meta_box_key', 'custom_meta_box_value' );

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 zain_ali