简体   繁体   中英

WordPress Multisite switch_to_blog

I using WordPress multisite and I have a script not tied to a theme nor a plugin:

$blog_id = (isset($_REQUEST['site']) ? $_REQUEST['site'] : 5) ;
switch_to_blog($blog_id);
echo get_option('blogname');

Above does not work it defaults to 1 and if I echo $blog_id it outputs the correct value. The code below works blog_id is hard coded

switch_to_blog(10);
echo get_option('blogname');

I need to be able to change the blog_id on the fly

我遇到了同样的问题,事实证明您不被允许使用$ blog_id,因为它被wordpress使用,更改了变量名,问题就消失了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM