i am using wordpress multisite. i am creating a function that when you post on 1 site, it will post the same post on another blog if required.
i am currently using switch_to_blog(), here is my code:
switch_to_blog(2);
$my_post = array(
'post_title' => $post_title,
'post_content' => $post_content,
'post_status' => 'publish',
'post_author' => $post_author,
//'post_category' => array(8,39)
);
// Insert the post into the database
wp_insert_post( $my_post );
restore_current_blog();
the above is ran on a save_post action. it works fine and posts to both blogs. The only issue is on the blog i switch to wp_insert_post gets stuck in a loop and have thousands of posts added!
Any reason why that would happen from the above code?