How to get custom post_author?

Question

I have a post type that inserts email as a post. I also created users according to those emails.
This is how I added my post type.

$post_array = array( 
                'post_content'  => $mail['body'], 
                'post_title'    => $mail['header']->subject,
                'post_type'     => 'faqpress-tickets',
                'post_author'   =>  $user_name,
                'post_status'   => 'publish',
                'meta_input'    => array(   
                    'User'      => ucwords(strstr($mail['header']->fromaddress, '<',true)),
                    'From'      => preg_replace('~[<>]~', '', strstr($mail['header']->fromaddress, '<')),
                    'Email'     => $mail['header']->Date,
                    'ticket_id' => preg_replace('~[<]~','',strstr($mail['header']->message_id, '@',true)),   
                    ),
                );
                    wp_insert_post( $post_array );

This is how I added the users:

if(email_exists($email)){
    add_post_meta($post_id, 'faqpress_ticket_username', $email, True);  
    add_post_meta($post_id, 'faqpress_ticket_email', $user, True);
 }
    else{
         $userdata = array(
        'user_login'    => ucwords(strstr($mail['header']->fromaddress, '<',true)),
        'user_pass'     => '',
        'user_nicename' => ucwords(strstr($mail['header']->fromaddress, '<',true)),   
        'display_name'  => ucwords(strstr($mail['header']->fromaddress, '<',true)),
        'user_email'    => strstr($mail['header']->fromaddress, '<'),
        'role'          => 'support_customer',
    );
    wp_insert_user($userdata);
}

Now I want the post to have the author the same as the user I just created.
How do I achieve that?

0
Rohit KC 1 year 2022-01-06T01:29:16-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse