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-built website which pulls data from WordPress.

I've included wp-blog-header.php in my page and it is all set, I can get my posts, featured image, titles, anything I want, wherever I want.

Now I'd like to add new languages to my website, so I've set up multisite so I can have one site for each language. How can I access information from a specific site? I'm using subfolder method, but there is no example.com/sub/wp-blog-header.php file to include!

Any Ideas on how to pull data of specific site on external pages?

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

You can use the switch_to_blog() function to switch the scope to a specific site and access data from that site:

require_once( '/path/to/wp-load.php' );
switch_to_blog( 3 );
$option = get_option( 'admin_email' );
restore_current_blog();

Also, you should use wp-load.php when using WordPress API in your own project, not wp-blog-header.php

share|improve this answer
add comment

In almost the same way, you just need to set $_SERVER['REQUEST_URI'] to the URL which you would have accessed if you were accessing a single wordpress install. Wordpress parses that variable to determine which site you are trying to get to and then sets to lok only at the relevant DB tables.

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.