Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
1  
Why not to use switch_to_blog in order to insert your posts? –  konus Apr 29 '11 at 14:32

1 Answer 1

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
...
...
restore_current_blog();

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

share|improve this answer

Your Answer

 
discard

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.