1

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?

2 Answers 2

2

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

0

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.

Your Answer

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

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