WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Why you are not using the built-in Wordpress service to select authors img ? – amit Aug 4 '12 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 – pixelngrain Aug 4 '12 at 20:34
you have to add custom field manually then.. ? – amit Aug 4 '12 at 20:39

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.

share|improve this answer
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 – pixelngrain Aug 5 '12 at 4:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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