I'm using php to dynamically create a custom post, and I need the author to be someone other than the logged in user. I found this http://stackoverflow.com/questions/5759359/wordpress-manually-set-the-author-of-a-post-in-php but I'm wondering if there is a way to do it after the post is already inserted. I guess I could just do a db query...
If you know the ID of the author you can use wp_insert_post specifying the ID and the author ID to it.
The trick is to specify the ID to update the post. See
For simplicity and relevancy between this question and another question asked on Stack Overflow (wordpress - manually set the author of a post in php -- As linked by OP here on WPSE.).
The way around it is to use the filter hook
Example Usage of filter hook
This can be particularly nice for inserting or updating posts using
Note: You will want to be sure to disable the support for
If this is a custom post type and you don't want an author assigned to a post you can remove 'author' from
If you still need author support for your post type, this would make much more sense to just do this in post.php / post-new.php by filtering the author metabox.
The solution is to add a none or null user to the dropdown using wp_dropdown_users
*Note: This example also moves the author div right above the publish button.
Im sure you notice all the extra conditional checks for $selected. It might be overkill but eliminated any issues with editors not being able to change an author to none from previous published posts.