If you know the ID of the author you can use wp_insert_post specifying the ID and the author ID to it.
$id = $post->ID; // change this to whathever
$user_id = '4'; // change this too
$the_post = array();
$the_post['ID'] = $id;
$the_post['post_author'] = $user_id;
wp_insert_post( $the_post );
The trick is to specify the ID to update the post. See wp_insert_post().
Related Posts:
- How can I show a custom post type for users in the authors.php file?
- Auto-generated posts not showing in backend (but being counted!)
- create parent post using wp_insert_post
- Post author for revision not being set on update/insert
- wp_insert_post wrong post type [closed]
- Display an authors post on a single page only when they are logged in
- Update post if exist from PHP
- How to handle new post from API request?
- Restrict category access to specific users/groups. Author always has access
- Custom post type title of each author in his own post
- Display author box on just certain category posts?
- Display custom post counts for author , not default posts
- Need to display author’s email id in the “Edit post” field in wp dashboard. How do I do this?
- Delete Post by User
- How to insert post 6 times after user register like ask.fm
- WordPress Author Posts Review After Every Change In The Same WordPress Post
- Submit post and upload image from front-end
- Linking Two Post Types
- Adding %author% in custom post type URL structure?
- Pull Two Posts Into Custom Post Type `single-cpt.php`
- Problem excluding category from get_next_post
- Why is the »_builtin« parameter not advised in »register_post_type()« for custom post types?
- How to let custom post type posts show in standard post archive (like in homepage)?
- Rewrite custom post & taxonomy to share same URL path
- Recent comments on author page?
- Get the post children count of a post
- Quickest way to get last or oldest post date – WP Query
- How to use custom fields to enable sticky posts on custom post types?
- get_template_part for custom post type content not working
- Show Two custom Post type and their posts on category page
- count_many_users_posts except current logged in user?
- WordPress post count not showing for custom post type author
- Filter post by current 2 differents users id
- How to auto increment post title & post slug field?
- Shortcode for display posts on home page show only one post
- How to Separate CPT From Regular Posts?
- Remove rows in the manage post/page view
- Display only one post each WEEK
- How to add a custom-post-type post within another custom-post-type post edit screen using AJAX?
- Cron job for creating posts not excecuting properly
- Set a checkmark in a category based on a URL-parameter
- Portfolio Page for Classic Posts
- Limit the post for differents custom post type in the same wp_query
- Some posts from custom post type to subdomains
- wordpress remove views from action links in a custom post
- Programatically inserted posts not showing in Posts Table
- Programmatically change post visibility on save_post action return a 500
- Stores category posts in an array
- Select other roles as custom post authors
- Why does wp_update_post causes white screen?
- Add to ‘action’ within post.php to allow more actions when editing a Custom Post Type in a plugin
- Get post format
- Template code to split a post and print a custom field?
- Send post changes to set email addresses (not users or subscribers)
- Display post from custom post type
- Custom Post type registering as page post type
- Custom Posts and Posts – next_post_link and previous_post_link not working together
- Enable comments for post when comments meta box removed
- How to: Add a publish immediately button when editing custom WordPress posts?
- Extending post by email
- Checking for custom field in admin pages
- “Author” custom post type
- Custom Posttype URL
- Display custom post front end filter by ACF equals current user
- Is it possible to pin a post in second position from top
- Best way to fix bad count on All | Mine | Published
- open custom post type in popup window instead of page
- How to display custom field in product description?
- How do I find the count of the current post?
- Permalink for specific post type
- SEARCH QUERIES – REVERSE OUTPUT
- Adding specific custom fields (images) to post excerpt
- Add input radio menu to post
- How to properly get the wp_postmeta.meta_value of a custom post type in specifics?
- How to add custom PHP code in post header?
- How to manage a dynamic multi-level page hierearchy system?
- Custom Post By Category
- custum post inner page not taking single-gallery.php? it redirecting to archive page
- Change Custom Post Type to Post + Category
- When post is Published, insert into custom table a number – custom post type
- Get post from Category by Priority
- Submitting custom post from frontend,jQuery ajax, and custom validation – can’t find proper place to insert wp_insert_post()
- I want to link an author to everything from any post type that they publish on the website
- Cannot use pages created on WP
- Calling specific page with wp query
- How to get Last post Id of custom post type in wordpress
- erase post excerpt limitation [×]
- Display a post count from a custom metabox selection
- Show a custom field instead of username in the backend author area
- Custom Post Type children and grand-children in one list
- Custom Post Type post not appearing
- How to call wordpress custom post type page
- How to filter homepage posts by popularity? [closed]
- How to display Author Profile based on Custom field value
- Automatically add custom taxonomy when meta value gets to a set number or beyond
- How to make a non-public post on wordpress approval?
- How to get permalink of post based on post name?
- Using wp_insert_post to create custom posts with ACF image field
- Change post-name when inserting new Post if Specific Category is selected in WP
- I am having a problem with fetching product data in the Gutenberg block editor