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
0
  // set Selected Post CATEGORY cheked 
    wp_set_object_terms( $post_id, array((int)$_POST['movies_cat']), 'movies' );
} else{ die("check seccurity");}  

// This bellow given code add on design page

<p class="meta-options hcf_field"> <label for="movies">The Categories</label> <?php wp_dropdown_categories( 'taxonomy=movies&name=movies_cat&show_option_all=Select a category' ); ?> </p>

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.