Publish Posts to All Sites in WordPress Multisite
Actually, I’m about to show you not only how to publish posts to all sites in your WordPress multisite network but also how to sync the changes made in those posts between sites. In other words, let’s talk about ways of setting up shared content between sites in a multisite network.
There are two ways of how you can accomplish that:
- When a post is published or updated on a main site of your network (you can decide yourself which one is going to be main or simply use the
get_main_site_id()function), it will be automatically published or updated on all sites in the multisite network. In the first method, we’re going to do it programmatically and usesave_postaction hook to trigger that. - The second method is similar to the first one; however, the difference is that you can decide which sites of the multisite network you’re going to publish posts to or sync their changes. And we’re going to use a WordPress plugin – Simple Multisite Crossposting, in that case.
Oh, yes, there is also a third way, which is completely different – the idea is indexing content and then having access to it anytime from any site; my other plugin can help you with that.
1. Post to All Sites in a WordPress Multisite Network Programmatically
Let’s begin with the programmatic way, but you can just skip this chapter and continue straight to the plugin way. By the way, the code below is similar to the code we used in this tutorial when moving network posts (or pages) from one site to another.
As you may probably guess, the first thing we need to do here is to decide which one of the sites is going to be the main one. We can do it manually or use the get_main_site_id() function, for example. From this specific site, we’re about to automatically post to all the other network sites.
Below is the snippet that you can use either on the main site of your network only or activate it network-wide.
/*
* WordPress Multisite: Post to all 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;
}
// actually we need only "publish" status
if( 'publish' !== get_post_status( $original_post ) ) {
return;
}
// here you can check whether you're on the main site for example
$main_site_id = get_main_site_id();
if( $main_site_id !== get_current_blog_id() ) {
return;
}
// prevent "Fatal error: Maximum function nesting level reached"
remove_action( 'save_post', __FUNCTION__ );
// time to get all sites
$site_ids = get_sites(
array(
'fields' => 'ids',
'site__not_in' => array( $main_site_id ),
'number' => 50, // 100 by default
)
);
// 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
$post_terms = wp_get_object_terms( $original_post_id, 'category', array( 'fields' => 'slugs' ) );
$post_meta = get_post_custom( $original_post_id );
foreach( $site_ids as $site_id ) {
switch_to_blog( $site_id );
// if a 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' => 'any' ) ) ) {
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();
}
}Some notes:
- Our code shouldn’t duplicate drafts, so I added a
get_post_status()condition. But if you need to sync drafts as well, you can skip that condition. - Using
remove_action( 'save_post' ...is critical; otherwise, the function will be called inside itself many times because we’re usingwp_insert_post()which also has asave_posthook inside. As a result, the fatal error: “Maximum function nesting level reached.” - I am also using the
get_sites()function because we decided that we’re going to post to all sites in a multisite network at once, but, of course, you can just provide blog IDs as an array instead. As you can see, I used asite__not_inparameter to exclude the current site, obviously. - The rest of the code is a little bit simplified; I just get post categories and custom fields and add them to cross-posted posts as well, but what if you have some custom taxonomies? And how about featured images? If you need a complete solution, please check the plugin below.
2. A Plugin for WordPress Multisite that Allows You to Post to All Sites
It is time to talk about the plugin approach.
In this chapter, we will talk about my Simple Multisite Crossposting plugin.
At this moment, the plugin supports almost everything you can imagine: custom post types and taxonomies, featured images, ACF and similar metabox plugins, WooCommerce products, pages created with Elementor, and so on.
Here is what it looks like in the WordPress Block editor:

The question you might have at the moment: “Wait, but we need to select sites using these checkboxes; is there a way to automatically post to multiple sites?” The answer is “Yes!”. In that case, you just need to turn on the “Auto mode” option in the plugin settings.

Have any questions left? Let me know in the comments below.
Misha Rudrastyh
Hey guys and welcome to my website. For more than 15 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!
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
Hi Martin,
It is ready, I hope you will enjoy it
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_postaction hook.hey – is this idea of the plugin still in consideration?
would also LOVE that!
Hey Oliver,
Yes, it is :)
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_postwhich is now 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 :)
Reaaaalllyy nice !!!
It’s working fine !!
Thank you !!
I have a question : the feature “publish on” with checkboxes ? Only avalaible on your plugin ?
Thanks,
Steven.
Yes :)
Hello,
I’m interested in your plugin.
In fact, I have a multisite network with subdomains and domains, for example:
sub1.domain1.com
sub2.domain1.com
sub3.domain1.com
…
And:
sub4.domain2.net
sub5.domain2.net
sub6.domain2.net
domain3.com, domain4.com,
…
I want to manage posts (WRITE AND UPDATE! AUTOMATICALLY)
from sub1.domain1.com to ONLY sub4.domain2.net
sub2.domain1.com to ONLY sub5.domain.net
sub3.domain1.com to ONLY sub6.domain2.net
from domain or subdomain X to ONLY domain or subdomain Y.
…
The subdomain or domain name doesn’t matter, the important thing is that it’s from site A to site B (identified by their respective IDs) and that Writing, updating, trash, images, etc., are fully handled on the second site as if I were on the first site.
From site A to site B.
Of course, all these sites are on the same network.
Is this possible with your plugin & with a single plugin?
In any case, do you have a solution to suggest?
In any case, the solution must not create any new tables in the database.
Thank you.
Hello,
Yes, everything you have mentioned is possible with the plugin