Title: wp_insert_post in current blog
Last modified: August 20, 2016

---

# wp_insert_post in current blog

 *  [Bernat Torras (a11n)](https://wordpress.org/support/users/bernattorras/)
 * (@bernattorras)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/wp_insert_post-in-current-blog/)
 * Hi! I’ve just created an WPMS installation with two sub-sites. They both share
   the same theme, and in one page, the user should be able to insert a post into
   the current site.
 * I’m trying to use the function switch_to_blog() to switch to the current blog
   and then insert the post with wp_insert_post() and update_post_meta() but the
   posts are always inserted into the main site.
 * Anybody knows what am I doing wrong? Here’s the code:
 *     ```
       $title = $_POST['title'];
       $author_id = $_POST['author_id'];
       $reference = $_POST['reference'];
       $blog_id = $_POST['blog_id'];
   
       $my_post = array(
        'post_title' => $title,
        'post_status' => 'pending',
        'post_author' => $author_id,
        'post_type' => 'order'
       );
   
       switch_to_blog($blog_id);
       $new_id = wp_insert_post( $my_post );
       update_post_meta($new_id, "reference", $reference);
       restore_current_blog();
       ```
   
 * Thanks in advance!

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Moderator [Ipstenu (Mika Epstein)](https://wordpress.org/support/users/ipstenu/)
 * (@ipstenu)
 * 🏳️‍🌈 Advisor and Activist
 * [14 years, 9 months ago](https://wordpress.org/support/topic/wp_insert_post-in-current-blog/#post-2233215)
 * There are already plugins for that 🙂 No need to reinvent the wheel.
 * Broadcast a post/page to other blogs. Whitelist, blacklist, groups and automatic
   category+tag posting/creation available.
    * [http://wordpress.org/extend/plugins/threewp-broadcast/](http://wordpress.org/extend/plugins/threewp-broadcast/)
 * Allows you to duplicate posts and pages to multiple sub-blogs at once.
    * [http://wordpress.org/extend/plugins/multipost-mu/](http://wordpress.org/extend/plugins/multipost-mu/)
 *  Thread Starter [Bernat Torras (a11n)](https://wordpress.org/support/users/bernattorras/)
 * (@bernattorras)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/wp_insert_post-in-current-blog/#post-2233242)
 * Thanks for your reply Ipstenu.
 * As I can see those plugins are for publishing via backend… What I’m trying to
   do is to publish via a frontend form, so the users could insert posts without
   the need of going to the backend.
 * I’m sure that WP have its own way to do that!
 * Any ideas?
 * Thx
 *  [Andrea Rennick](https://wordpress.org/support/users/andrea_r/)
 * (@andrea_r)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/wp_insert_post-in-current-blog/#post-2233255)
 * The P2 theme.
 * And using switch_to_blog for this is… no. not the the way to go. That function
   is an admin function, not a frontend one.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘wp_insert_post in current blog’ is closed to new replies.

 * In: [Networking WordPress](https://wordpress.org/support/forum/multisite/)
 * 3 replies
 * 3 participants
 * Last reply from: [Andrea Rennick](https://wordpress.org/support/users/andrea_r/)
 * Last activity: [14 years, 9 months ago](https://wordpress.org/support/topic/wp_insert_post-in-current-blog/#post-2233255)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
