0

Usually, I write posts as admin, as this is more comfortable from the blog administration point of view. But I want the posts to be assigned automatically to another existing user with editor privileges. How to do this?

1 Answer 1

2

You can try using wp_insert_post_data for the task. Something like:

function assign_new_post_to_specific_author( $data , $postarr ) {

  // Where author_ID is the ID of the author you want to assign the new post
  $data['post_author'] = author_ID; 

  return $data;

}

add_filter( 'wp_insert_post_data', 'assign_new_post_to_specific_author', '99', 2 );

Tried it on c9.io and it works, but you need to check the filter priority for yourself.

2
  • Works for the new posts and also for the re-saved. Maybe the last must be avoided, but for me is OK. Thank you!
    – Yuri
    Commented Jul 29, 2015 at 21:33
  • 1
    Yes you can do some check whether the post is in draft or scheduled or something like this. codex.wordpress.org/Plugin_API/Filter_Reference/… - Here are all things you can access via the $data variable. In future you can build more flexible management system. Commented Jul 29, 2015 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.