You can use the function switch_to_blog()
for this
$other_id = 1234 // the id of the other blog to save the post to
switch_to_blog($other_id);
$my_post = array(
'post_title' => $post_title,
'post_content' => $post_content,
'post_status' => 'publish',
'post_author' => $post_author,
);
// Insert the post into the database
wp_insert_post( $my_post );
restore_current_blog();
There is a pitfall if you execute this code on the save_post
hook, because wp_insert_post
also calls save_post
and you end up in an infinite loop. This post on Stack Overflow gives a solution for that.
Related Posts:
- How can I have the posts from one word press blog show on the presentation page of another word press site
- Get image paths from RSS feeds
- Disable WordPress’ blogging functionality and disable ‘posts’
- How to cache a shortcode functions output?
- Querying post from a multisite network
- How do I convert a mathematical Microsoft Word document to a WordPress blog post?
- how to display full post with pagination on home page
- blog page showing only first post
- Strange switch_to_blog() issue
- Showing random content / pictures from earlier posts in a sticky post?
- How to hook a function only when I need to delete permanently a post?
- Pull posts from another wordpress install on same server
- Custom excerpt length filter doesn’t work
- How to get the post’s parent ID?
- Limit Gutenberg blocks available to users to choose from
- Remove certain post-formats from showing in blog?
- How blog page in WordPress works : blog page retrieve first post ID
- Blog Posts in Custom Menu
- Add blogs to “Blogs i Follow” sidebar [closed]
- How to show last post of each website of a MU wordpress in HomePage
- Choose whether to automatically add a taxonomy with the same name as the post
- Display posts from a different website on Genesis Responsive Slider
- add new post default view
- Show certain posts in a LIST format that members have been granted access to
- How to display content from the main blog on another from multisite network as it would be its own
- Append class to posts page
- Multisite: Can’t Post or Create Categories
- How to disable WordPress blog folder
- Pagination with an array of post objects?
- How could I change my Permalink from blog to custom structure? [closed]
- WordPress Multisite – Create Default Post and New Category On New Site Install
- Set static page/post from another blog on same network
- Single.php – Get Current Parent Category
- How to remove in-line style of WordPress’s post content only?
- How to WP_Query() from multiple blogs and order them?
- WP move posts to different path
- Is it possible to filter the main loop to exclude posts from a specific category?
- Append ‘Continue Reading’ link if post length is more than 3 lines of text?
- How do I show posts from another wordpress installation?
- older blog posts not showing in new theme
- Display password protected posts to logged in users
- Why won’t pagination work?
- WordPress Query Posts From Category Post on Static Page
- How to create a page that shows the last 10 posts?
- Exclude post category in a blog page
- How to set a certain Custom Template to a Single Blog Post
- Change Author Name to Sitename on Frontend
- Sidebar on single.php not showing up
- Cannot select certain authors for posts after import
- why the posts queried from sql is more than those showed on the page?
- Prevent duplicate pages from being added
- posts and cms and posts again
- Changing The Default Header POST Title and Description text by category in wordpress
- Separate blog and reviews categories
- why my urdu text is not aligned properly when written in wordpress blog post?
- Older blog posts not showing up on WordPress
- Pagination not give another posts
- “Blog pages show at most” in setting not working
- unable to write to the database while uploading images
- Sticky Post Doesn’t always work
- Post Image Gallery After Content Function messes with other content
- Single Post Gallery Using Shortcode
- How can I create a ‘sub-blog’ which has its own sidebar on individual posts?
- Displaying all posts from other sites on the network on one site
- blog post not accesible on click [closed]
- How to fix wordpress blog post error? Can anyone help to fix this issue?
- How to pull sticky post permalink inside php?
- WordPress empty page! what is wrong with this code?
- Multisite how to display merged posts from two sites and sort by latest date?
- Pagination Stops
- Bulk find & replace on WordPress posts/pages (minus image paths)
- Customizing a new page used for blog posts with Avada theme
- Blog featured images disappeared on my homepage
- Blog images not showing on homepage
- How to generate an HTML link automatically from URL in a users’ post
- Populate a drop down list with post titles across a multisite network
- Multiple Pages – Seperate blogs
- Word /blog/ in slug post, problems in CPT. Solutions?
- How to put the WordPress blog into theme
- Why the blog posts is not showing?
- Blog styling in SASS
- Hide first blog post in content and output it in widget
- How to get posts from network blog
- Page updates appear in Preview but not live version?
- Sorting Posts by Date – get_blogs_of_user_id()
- Users cannot post when editor or admin on more than 1 site on multisite
- new blog post does not appear in blog after publishing
- Posts don’t appear on the Blog page
- making a few sites in wordpress
- Wanting to apply different featured images for each post
- long blog post on self hosted wordpress blog not displayed
- WordPress Custom Theme: My site shows the same posts on Page 1 and Page 2 and so on [duplicate]
- Post only showing on homepage when Logged in – direct URL still working
- The page that displays Posts on homepage
- How to add a widget area between blog posts in Genesis Framework?
- How to save the same post in multiple blogs?
- Do I need to create a multisite for querying posts from multiple WordPress sites?
- Need to show birthday of custom post type(Famous people in this case) in elementor. Date of birth set in custom fields
- Site ‘Categories’: save an admin global setting with post metadata [closed]
- users followin the blog post author