Retrieving data from specific multisite blog

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.

Read More

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?

Related posts

Leave a Reply

2 comments

  1. 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

  2. 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.