Hello All!
I got this puzzling beginner issue. It's my first Multisite install, latest versions of all, no plugins, and when I am trying to use in a page template the switch_to_blog function, I get this :
Fatal error: Call to undefined function switch_to_blog() in /SITES/Sitename/wp-content/themes/themename/page.php on line 28
with line 28 : switch_to_blog(1);
I must do something wrong, but it looks the function itself is not installed, though the function's file is there (as it should be in any normal install).
Is there a way to cleanly create the function, declare it or activate it ? I tried copy the function switch_to_blog to functions.php, and there is does not complain but is not working (i got the article from the CURRENT blog). but then error make it stop to restore_current_blog(); with the same fatal error...
I don't know where to begin... what might help you understand the issue ? THANKS in advance.
G.
Hello All!
I got this puzzling beginner issue. It's my first Multisite install, latest versions of all, no plugins, and when I am trying to use in a page template the switch_to_blog function, I get this :
Fatal error: Call to undefined function switch_to_blog() in /SITES/Sitename/wp-content/themes/themename/page.php on line 28
with line 28 : switch_to_blog(1);
I must do something wrong, but it looks the function itself is not installed, though the function's file is there (as it should be in any normal install).
Is there a way to cleanly create the function, declare it or activate it ? I tried copy the function switch_to_blog to functions.php, and there is does not complain but is not working (i got the article from the CURRENT blog). but then error make it stop to restore_current_blog(); with the same fatal error...
I don't know where to begin... what might help you understand the issue ? THANKS in advance.
G.
Some time ago, but i ran into exactly the same misbehavior.
Have your multisite activated and installed correctly.
Because WordPress is just loading the functions when a multisite is really active.
Here the code from wp-settings.php
file around line 137 on WP 6.1.1
if ( is_multisite() ) {
require ABSPATH . WPINC . '/class-wp-site-query.php';
require ABSPATH . WPINC . '/class-wp-network-query.php';
require ABSPATH . WPINC . '/ms-blogs.php'; // <--- switch_to_blog() is in here!!
require ABSPATH . WPINC . '/ms-settings.php';
} elseif ( ! defined( 'MULTISITE' ) ) {
define( 'MULTISITE', false );
}
Here i found a long read tutorial which helped me a lot: https://multilingualpress.org/docs/how-to-install-wordpress-multisite/
But there should be alternatives findable anyway.