include multiple wp-blog-header.php from different blogs

I want to include more than one wp-blog-header.php like the following.$config = array(array("path" => "

I want to include more than one wp-blog-header.php like the following.

$config = array(
    array(
        "path" => "/path/to/blog/1/"
    ),
    array(
        "path" => "/path/to/blog/2/"
    )
);


foreach($config as $site){
    include($site['path']."wp-blog-header.php");
    echo get_site_url().' '.$site['path'].'<br>';
}

I get echo out the first site_url 2 times. So i believe there wordpress doesn't connect to second blog.

Is there a way to reset connection and everything which was included?

I want to include more than one wp-blog-header.php like the following.

$config = array(
    array(
        "path" => "/path/to/blog/1/"
    ),
    array(
        "path" => "/path/to/blog/2/"
    )
);


foreach($config as $site){
    include($site['path']."wp-blog-header.php");
    echo get_site_url().' '.$site['path'].'<br>';
}

I get echo out the first site_url 2 times. So i believe there wordpress doesn't connect to second blog.

Is there a way to reset connection and everything which was included?

Share Improve this question asked Jul 15, 2019 at 8:37 deluegdelueg 1071 silver badge5 bronze badges 1
  • 1 What problem are you trying to solve with this solution? This is almost certainly a dead end and a red herring – Tom J Nowell Commented Jul 15, 2019 at 9:55
Add a comment  | 

1 Answer 1

Reset to default 2

This will never work, you cannot include wp-blog-header.php multiple times from different installs.

After you include the first blog header, all of the WP functions are now present in the global namespace, all the databse details set, plugins and theme loaded, etc. In order to reset things you would need an entirely new request, defeating the point.

If your goal is to gather data from multiple instances there are better solutions:

  • A multisite installation, allowing switch_to_blog() to do this
  • Calling the REST API ( this can be done via JS or even a different program written in a different language )
  • WP CLI commands

But loading the code of multiple WP installations at the same time is not a solution, and will never work

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745322381a4622500.html

相关推荐

  • include multiple wp-blog-header.php from different blogs

    I want to include more than one wp-blog-header.php like the following.$config = array(array("path" => "

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信