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 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
add comment

1 Answer

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
add comment

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.