Given a user id, $user_id, and post id, $post_id, how can I programatically update a wordpress post author?
Note: these posts are already created and the author cannot be set upon creation. Another process is creating the post and defaulting to the admin as the author. I don’t have access to creating the post but have access after it is created.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
It shouldn’t be any problem. Try this:
$arg = array(
'ID' => $post_id,
'post_author' => $user_id,
);
wp_update_post( $arg );
Method 2
you can also just add another admin account. delete the one that’s authoring the posts and WP will ask where to assign posts. Choose preferred author, done.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0