wp_insert_post() creating duplicate posts for Custom Post Type
-
I am creating new plugin where I have displayed one form using shortcode. On submission of form, I want to create user and want to add post to my Custom Post Type.
I am able to create new user and I am using wp_insert_post() to do so. The issue is, post is getting inserted twice (duplicate). Below is my code for this :
if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['register_doctor'])) { $docdata = array( 'first_name' => $doc_fname_register, 'last_name' => $doc_lname_register, 'user_login' => $username, 'user_email' => $doc_email_register, 'user_pass' => $doc_conf_pass_register, 'role' => 'doctor' ); $user_id = wp_insert_user($docdata); $post = array( 'post_title' => $post_title, 'post_content' => 'test', 'post_type' => 'search_doctors', 'post_status' => 'publish', 'post_author' => 1 ); $post_id = wp_insert_post($post, $wp_error = ''); } }
One proper user is getting created but posts are getting created twice here. I am stucked here.
Any help on this will be highly appreciated. Thanks in advanced.
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘wp_insert_post() creating duplicate posts for Custom Post Type’ is closed to new replies.