Copy posts from one blog to another in multisite environment

To copy a post from one blog to another you can do something like this:

function copy_post_to_blog($post_id, $target_blog_id) {

   $post = get_post($post_id, ARRAY_A); // get the original post

   $post['ID'] = ''; // empty id field, to tell wordpress that this will be a new post

   switch_to_blog($target_blog_id); // switch to target blog

   $inserted_post_id = wp_insert_post($post); // insert the post

   restore_current_blog(); // return to original blog
}

Leave a Comment