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
- How to Display Network Post Count?
- Disable WordPress’ blogging functionality and disable ‘posts’
- How to cache a shortcode functions output?
- Querying post from a multisite network
- How to get a post content from another wordpress blog/site?
- How do I convert a mathematical Microsoft Word document to a WordPress blog post?
- widget should display post archive by year and on click also by month
- how to enable different number of revisions for different blogs when using WPMU?
- how to display full post with pagination on home page
- blog page showing only first post
- Strange switch_to_blog() issue
- Single Post Gallery Using Shortcode
- 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?
- How to create post in WP network using WP-CLI
- Side by side blog posts that are tied together
- Pull posts from another wordpress install on same server
- How to show a full post, not just an excerpt
- Query posts from different categories in multisite
- Custom excerpt length filter doesn’t work
- How to get the post’s parent ID?
- Limit Gutenberg blocks available to users to choose from
- Blog Posts not showing title
- Portfolio + Blog: multisite or plugin?
- Multisite – Get current post id
- Remove certain post-formats from showing in blog?
- How blog page in WordPress works : blog page retrieve first post ID
- Where is the “Posts”/”Blog” template?
- Cannot select certain authors for posts after import
- why the posts queried from sql is more than those showed on the page?
- How to separate each individual blog post?
- Direct some posts to only appear on a specific 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?
- Create a List of Widgets, where each widget holds three attributes
- 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?
- Use posts from old db by changing prefix
- Pagination Stops
- Bulk find & replace on WordPress posts/pages (minus image paths)
- How to backup WP blog posts to computer, not new site
- Customizing a new page used for blog posts with Avada theme
- Blog featured images disappeared on my homepage
- Blog images not showing on homepage
- Multisite Issue on Subdomain’s article pages
- Blog Page doesn’t show summary but full content
- How to generate an HTML link automatically from URL in a users’ post
- Get posts from category from custom query
- Populate a drop down list with post titles across a multisite network
- My posts page is missing the page title
- Blog Post slider not working
- 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?
- Edit Posts Page but not category specific pages?
- Blog styling in SASS
- Link post to blog from a static page
- 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
- How to link two news page multilingual press
- new blog post does not appear in blog after publishing
- Posts don’t appear on the Blog page
- making a few sites in wordpress
- 2 tick boxes appearing below comments
- 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
- Posts not showing up on Blog page
- 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
- Permalink issue with new blog posts > getting 301 redirect
- Blog page shows the whole blog post instead of the excerpt or summary with the feature image only
- Unable to create categories and tags for posts in wordpress multisite