I am merging Wordpress into a existing system and require our users to be able to make posts to a multi-site WP install. I have a database table that will link our own member to specific blog IDs and stuff, so there will be no need for user/logins as far as WP is concerned.

What I really need to know is how to run certain WP functions outside of WP itself - on a completely different domain infact (but same server). I have tried simply including wp-load.php in our existing admin panel but as soon as I do it redirects to the main site - I assume because the domains do not match:

domain1.com and domain2.com are both on the same server, domain1.com is the WP MU setup, on domain2.com in our own admin area I am including wp-load.php and as soon as I do it redirects me straight to the homepage of domain1.com.

Is it even preferable to do it this way? I have seen a few examples where people have directly queried the WP database to insert posts. but if that's the case I have to ask myself why I am even using WP for this project at all?! I am thinking about using WP XMLRPC API but I need more power than that and don't wish to turn in on really.

  • Have you tried require_once('./blog/wp-blog-header.php'); ?
    – Bainternet
    Commented Mar 3, 2011 at 12:38
  • Yeah, redirects all the same.
    – Dunhamzzz
    Commented Mar 3, 2011 at 12:59
  • redirects what? where are you requiring the file from server wise?
    – Bainternet
    Commented Mar 3, 2011 at 16:04
  • Updated question with info on the setup
    – Dunhamzzz
    Commented Mar 3, 2011 at 16:08

2 Answers 2


Ok I have cracked it, by spoofing the $_SERVER variable and pre-defing some constants, I was able to prevent Wordpress from redirecting after the inclusion of wp-load.php.

define('WP_USE_THEMES', false);
define( 'DOMAIN_CURRENT_SITE', $siteRow['domain'] );
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', $siteRow['wp_blog_id'] );

$_SERVER = array(
    "HTTP_HOST" => $siteRow['domain'],
    "SERVER_NAME" => $siteRow['domain'],
    "REQUEST_URI" => "/",

require_once WP_PATH.'wp-load.php';

$siteRow contains details about the target site. Note: This cannot be inside a function due to global variable restraints.


Hi I am a hacker not a programmer and I was able to get this to work quickly, but I think I was lucky.

I assumed the "define" commands were what was in my multisite dashboard and I added the $_server code to the top of my wp_insert_post script and it worked. I didn't use the following:

define('WP_USE_THEMES', false);

I used the following to select the blog although as it was the default blog maybe that wasn't necessary:

global $switched; switch_to_blog(1);

Or should I have put the "define" statements into the script?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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