I have code to create a new account and a new post. All of this works correctly, but I want the newly account created to be the author for the new post.

How can I do that?

/* Create account */

if (isset($_POST['task']) && $_POST['task'] == 'register')
$psw = $wpdb->escape(trim($_POST['psw']));
$email = $wpdb->escape(trim($_POST['email']));
if (email_exists($email))
$err = "Email addres exist";
$user_id = wp_insert_user(array(
'user_pass' => apply_filters('pre_user_user_pass', $psw) ,
'user_login' => apply_filters('pre_user_user_login', $email),
'user_email' => apply_filters('pre_user_user_email', $email),
'role' => 'author'

<form method="post" id="form_anunturi" enctype="multipart/form-data">
  <input type="text" name="title"/>
  <textarea name="desc"></textarea>
  <input type="text" name="email"/>
  <input type="text" name="psw"/>
  <input type="hidden" name="task" value="register"/>
  <input type="submit" value="Submit"/>


$date = array(
    'post_title' => $title,
    'post_content' => $desc,
    'post_status' => 'publish',
    'post_category' => array(
    ) ,
    'post_author' => $user_ID,
$post_id = wp_insert_post($date);

Read more here: Author for new post in wordpress


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, ,

Wordpress related questions and answers: