Using wp_insert_post() with Networking enabled

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)