Publish Posts to Multiple Blogs in WordPress Multisite
There are actually two ways of organising shared content between sites in Multisite Network:
- Post to multiple sites at once and then synchronising any changes, I will show show in this tutorial how to do it with code or with a plugin.
- Indexing content and then having access to it anytime from any site, my another plugin will help you with that.
Using save_post action hook
By the way the code below is similar to the code we used in this tutorial to move network posts from one website to another.
/*
* Post to Multiple WordPress sites at once
*
* @author Misha Rudrastyh
* @link https://rudrastyh.com/wordpress-multisite/post-to-all-sites.html
*/
add_action( 'save_post', 'misha_post_to_all_sites', 20, 2 );
function misha_post_to_all_sites( $original_post_id, $original_post ){
// do not publish revisions
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $original_post_id;
}
// actually we need only "publish" status
if( 'publish' !== get_post_status( $original_post ) ) {
return $original_post_id;
}
// prevent "Fatal error: Maximum function nesting level reached"
remove_action( 'save_post', __FUNCTION__ );
// here you have to specify blog IDs where you would like to publish the posts
$blog_ids = array( 2, 3 );
// let's get this post data as an array
$post_data = array(
'post_author' => $original_post->post_author,
'post_date' => $original_post->post_date,
'post_modified' => $original_post->post_modified,
'post_content' => $original_post->post_content,
'post_title' => $original_post->post_title,
'post_excerpt' => $original_post->post_excerpt,
'post_status' => 'publish',
'post_name' => $original_post->post_name,
'post_type' => $original_post->post_type,
);
// terms and post meta as well
$post_terms = wp_get_object_terms( $original_post_id, 'category', array( 'fields' => 'slugs' ) );
$post_meta = get_post_custom( $original_post_id );
foreach( $blog_ids as $blog_id ) {
switch_to_blog( $blog_id );
// if post with the same slug exists, do nothing
if( get_posts( array( 'name' => $post_data[ 'post_name' ], 'post_type' => $post_data[ 'post_type' ], 'post_status' => 'publish' ) ) ) {
restore_current_blog();
continue;
}
$inserted_post_id = wp_insert_post( $post_data );
wp_set_object_terms( $inserted_post_id, $post_terms, 'category', false );
foreach ( $post_meta as $meta_key => $meta_values) {
// we do not need these redirects
if( '_wp_old_slug' === $meta_key ) {
continue;
}
foreach ( $meta_values as $meta_value ) {
add_post_meta( $inserted_post_id, $meta_key, $meta_value );
}
}
restore_current_blog();
}
}
- Our code shouldn’t duplicate drafts, so I added
get_post_status()
condition on line17
, - Line
22
is critical, otherwise,misha_post_to_all_sites()
function will be called inside itself many times as we’re usewp_insert_post()
in it. As a result, fatal error: “Maximum function nesting level reached”, - You can also see on line
25
that we can post to multiple sites at the same time. You just have to specify blog IDs where you would like to cross-publish posts. If you want to post to all sites,get_sites()
function will help you to get all the blog IDs automatically excluding the current one, - On lines
42
and57
you can see that I only use categories here, but you can also add the appropriate code for any terms you’re using within your Multisite Network.
Do not want to mess up with the code? Check another solution below.
Using my plugin
When I first posted this tutorial I asked in the comment section if any of you guys need a plugin for this. I received a lot of answers “Yes” and the plugin is ready!
It supports custom post types and statuses, custom taxonomies and post thumbnails etc.
Here is how it looks in WordPress editor:


Misha Rudrastyh
Hey guys and welcome to my website. For more than 10 years I've been doing my best to share with you some superb WordPress guides and tips for free.
Need some developer help? Contact me
Yes, absolutely!
Interested in that plugin!
Yes, please!
Yes Please
YEEEEESSSS!!!
Yeeeeesss. Thank you
Yes please
yes please!
Yes :)
Did this get made? Because this would be amazing?
yes
Dear Misha,
yes, it would be great to have such a plugin – also as it looks so intriguing easy in your image example. Will you notify me, when available? Is there any timeline you think to get in running?
Kind regards, Martin
Yes please!! is this real yet?
Yes
Yeeeees!
Hi Misha
I have a multisite set up where I would like to publish content automatically on all sites automatically without having to make a choice with each post. This is because of the set-up I have which pulls API data and creates posts from it so I get 300-500 posts a day and I would just like to have these posts pushed out to all the blogs on the network after they are published on the main site. Your code seems to do half of what I need. Any help you can offer would be appreciated.
Thanks
Ronnie
Hi Ronnie,
The long story short, I can recommend you to use the code from this tutorial inside
save_post
action hook.Yes
Yes!
yep
Yes
Yes
hey – is this idea of the plugin still in consideration?
would also LOVE that!
Hey Oliver,
Yes, it is :)
Oh yes… thanks :)
Yes
yes
YES
Yes, please!
Yes please! Thank you.
Yes please!
Yes please! Thank you.
yes, please
thank you
Hi !
1 °/ Does the plugin work on different domain names?
Eg:
my-website-1.com
other-website-2.com
other-website-3.com
…
———————
2 °/ Are the posts duplicated for each site selected in the database or is it a single entry in the database?
———————
3 °/ Can we publish a “shared-post” from any site administration of the network
Hi,
1. Yes, sure
2. They will be duplicated for each website
3. Yes
Thanks for your help !
^^
yes thanks for the plugin
This doesn’t work for me. It copies the post title and content, but the categories and tags are not copied across. Any idea on why?
I have used the hook ‘wp_after_insert_post’ which is mostly working. This hook is fired after all meta and terms are updated.
Hello, the code works great! First of all thank you for it. However, I see two small optimization possibilities.
1. when I delete a post from the main page it is not removed from the subpage.
2. if I adjust a post from the main page e.g. the headline, text or image it will not be updated on the subpage either. Do you maybe have a solution for this as well? If these two functions is also already built in your plugin I would be very interested in it!
Hi Ibrahim,
Yes, both of these features are part of my plugin :)