How to get all post of the Main Site to the sub site in multisite network?

Hi Friends!

Sometimes if you want to get all post from main site into sub site. So please refer my below code.

switch_to_blog( $blog_id );
// put code for all post here.
restore_current_blog();

switch_to_blog($blog_id); = This is switch to the site in network  as per the ID.

You have added the main site id. So it will switch to the main site.

restore_current_blog(); = will restore the current blog.

I hope this article will help you 🙂

Blog Catagory : WORDPRESS