I trying get the categories in a function from a selected blog on my multisite with switch_to_blog, but I get the categories of the current blog, and I dont understand, why... I searched the solution on the net, but I dont find anything about this problem... Here is my code:
function getcatsfromblog(){
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );
$blog_id = get_blog_id_from_url( 'site2.network.com' );
// GET CATS
switch_to_blog( $blog_id );
$categories = get_categories( array(
'orderby' => 'name',
'order' => 'ASC'
) );
foreach( $categories as $category ) {
echo '<input type="radio" value="' . $category->name . '">' . $category->name . '</input>';
}
restore_current_blog();
}
getcatsfromblog();
Any idea, whats wrong with this? (I call this function with AJAX, but except of the swith_to_blog, everything working...)