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 have a custom post type set up on a subsite in a multisite network which the code is in a plugin to activate it only for the subsite.

I have some code that inserts a post using code but I belive it is trying to insert it into the main site. it is simply a php page with

require( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );

then some $_POST to grab some data and use that to create a post. This works fine in a standalone install of WordPress but on the multisite it does not work. Is there a way to choose the site to add the post to?

share|improve this question
up vote 0 down vote accepted

You probably need to switch your context to the subsite in which the posts need to be created. Have a look at the switch_to_blog() and restore_current() functions in wp-includes/ms-blogs.php See http://phpxref.ftwr.co.uk/wordpress/wp-includes/ms-blogs.php.source.html#l437

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.