Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8330955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:16:48+00:00 2026-06-09T02:16:48+00:00

I am developing my site and require to change post author id on the

  • 0

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.

Does the author info have to come from the custom field? Because you could do this straight in the UI manually.

  • Enable the “author” block in the display options when creating a post

  • Change the author in the drop-down menu

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
$png_gallery_meta->the_field('image_artist');
$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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:16:49+00:00Added an answer on June 9, 2026 at 2:16 am
    $post_id = $post->ID; // change this to whathever
    $user_id = '4'; // change this too
    
    $the_post = array();
    $the_post['ID'] = $post_id;
    $the_post['post_author'] = $user_id;
    
    wp_insert_post( $the_post );
    

    The code above will update the currently looped through post (via $post->ID) with an author with ID of 4.

    Read how wp_insert_post works here. Basically, if you pass it an ID of a post that already exists it will update that post with the new information you pass to it. (the author ID in this case)

    If you want to grab things from the custom fields you can use:

    $author = get_post_meta($this->ID, 'author_id', TRUE);
    

    More info on custom fields.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Strange question I know, but I'm developing a .net site, it's going to be
I am developing a site based all around photos. Some areas of this site
I am developing a site that will consist of one HTML page. The HTML
I am developing a site in rails which requires information whether any analytics like
I am developing site with WordPress and I'm newbie for WordPress. WP adds <p>
I'm developing web site that loads pages dynamically using the .load function. For example:
I am currently developing a site using ASP.NET MVC 3, I am using Nhibernate.
I'm developing a site which connects with Eway. I trying to make a Rebill
I'm developing a site on local server, so the url of the site is
We are developing a site on college and college authorities are not giving us

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.