I am developing my site and require to change post author id on the fly while publishing.

All post will be write and publish by admin but as content provided by different author and need to change post author id from admin to other author ( author id will get from custom field )

So how to do this on the fly while publishing.

Here is my theme metabox.php code I am using wpalchemy metabox script and below code is in my cpt loop php file

// getting custom field value from image_artist
// this is giving value like artist_login_name / id
$artist_info = $png_gallery_meta->get_the_value();

// to separate artist_login_name and id
$string = $artist_info;
$artist = substr($string, 0, stripos($string, "/") );

// getting first name and last name from user id
$author_first_name = get_userdata(basename($string))->first_name;

$author_last_name = get_userdata(basename($string))->last_name;

So I am using above code to get user info from custom field dropdown selection box. Now how can I use above value to change id on the fly while admin publish the post the post author id should change with above id value get from selection box. I hope now it is more clear.

  • Why you are not using the built-in Wordpress service to select authors img ?
    – Amit Kosti
    Aug 4, 2012 at 20:31
  • Because all author are only subscriber and I want to make it automated instead of manual which result wrong input sometime. As I am getting user id from custom field for the author so that id i want to add in post author id Aug 4, 2012 at 20:34
  • you have to add custom field manually then.. ?
    – Amit Kosti
    Aug 4, 2012 at 20:39

1 Answer 1


You need to hook into the save_post action filter, get the post meta field, and swap the ID's and fire the update_post function.

  • Yes I understood what you are saying but confuse how to use it. I have updated question with actual code. Please go through it once Aug 5, 2012 at 4:53

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.