1
if ( isset( $_POST['save'] )  ) {

    if(wp_verify_nonce($_REQUEST['_nonce'], 'submit-post')){

      // $userid = get_current_user_id();

            $atts = array( 
            'post_content'   => $_POST['content'], 
            'post_title'   => $_POST['title'],
           //'post_status'   => 'draft', /* It coulde be publish*/
            // 'post_excerpt'          => '',
            'post_category' =>  array('movies' => $_POST['movies']),
             //'comment_status'        => $_POST['comments'],
            'post_type'     => 'movies'
       // 'post_category' => array($_POST['movies'])


            );

           // $id = wp_insert_post( $postarr, $wp_error );
           $id = wp_insert_post( $atts, $wp_error );

           $fields = [
                    'movie_name',
                    'movie_release_date',
                   'movie_producedby',
                    'movie_starcast',
                    'movie_type',
                    'movie_genre',
                    'number_of_stars'
                   // 'movies'
            ];

            foreach ( $fields as $field ) {
                if ( array_key_exists( $field, $_POST ) ) {
                    update_post_meta( $id, $field, sanitize_text_field( $_POST[$field] ) );
                }
            }
    }
             else{ die("check seccurity");}

  }  //else{ die("check seccurity");}


            ?>     
                <form id="mvshortcode" name="mvshortcode" method = "post" action="" >

                <?php include plugin_dir_path( __FILE__ ) . './movieShortcodeForm.php';?>
                    <!-- <label for="title">Movie Title:</label>
                        <input type="text" name="title">                     
                    -->             
                    <input type="hidden" name="_nonce" value="<?php echo wp_create_nonce('submit-post') ?>">

                  <input type="submit" name="save">



                </form>
            <?php

}
  • Please add more explanation and write more about what you did and what you wanna do. – Amirition Apr 9 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.