Programatically change post author

admin2025-06-05  1

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.

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.

Share Improve this question asked May 4, 2015 at 16:15 italiansodaitaliansoda 4461 gold badge6 silver badges14 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 28

It shouldn't be any problem. Try this:

$arg = array(
    'ID' => $post_id,
    'post_author' => $user_id,
);
wp_update_post( $arg );

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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749122195a316552.html

最新回复(0)