Skip to content

Instantly share code, notes, and snippets.

@yoren
Forked from murdaugh/copy post to blog function
Created November 17, 2013 08:54
Show Gist options
  • Save yoren/7510999 to your computer and use it in GitHub Desktop.
Save yoren/7510999 to your computer and use it in GitHub Desktop.
<?php
function copy_post_to_blog($post_id, $target_blog_id) {
$post = get_post($post_id, ARRAY_A); // get the original post
$meta = get_post_meta($post_id);
$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
foreach($meta as $key=>$value) {
update_post_meta($inserted_post_id,$key,$value[0]);
}
restore_current_blog(); // return to original blog
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment