WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on a script that will drop articles directly into the wordpress database, using wp_insert_posts(). However, I have networking enabled and the wp_insert_post() reference page has no documentation relating to using wp_insert_post() to upload to a specific site on the network.

How can I do this with wp_insert_posts()? Or is their another function which does this?

share|improve this question
Why not to use switch_to_blog in order to insert your posts? – konus Apr 29 '11 at 14:32
up vote 4 down vote accepted

When using function like wp_insert_post() It will work on the currently active blog, meaning that if you are on a blog in your network with blog_id of 2 the the post you insert using wp_insert_post() will be inserted to that blog.

Now if you want to insert the post to a specific blog you can use switch to blog() function which will tell WordPress that "the current blog is" so you can use wp_insert_post() to insert to that specific blog.

Then to tell WordPress that what is the real current blog you can use restore_current_blog() so:

switch to blog($wanted_blog_ID);
your wp_insert_post() stuff

take a look at WPMU Functions to understand more about the available functions in a network.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.