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?
You can use the
switch_to_blog()
function to switch the scope to a specific site and access data from that site:Also, you should use
wp-load.php
when using WordPress API in your own project, notwp-blog-header.php
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.