In my root blog (1), i have a custom post type that can be linked to an existing blog of my network. It does so by recording in post metas the ID of the blog it is linked to. I use
_blog_id as a name for this data.
In a page of this root blog, i list these custom posts, and i easily retreive the meta i saved:
<?php while ( have_posts() ) : the_post(); $blog_id = get_post_meta(get_the_id(), '_blog_id', true);
Now, i have the ID of the blog i want information from, so i try the following:
switch_to_blog($blog_id); $blog_url = get_bloginfo('url'); restore_current_blog();
Unfortunately, that doesn't work because
$blog_url has the URL of the root blog.
switch_to_blog() works but not
restore_current_blog(), because subsequent calls to the LOOP functions now work in the sub-blog. For example, when calling
the_post_thumbnails(), the image source is referred by "/uploads/sites/2/2014..." while i'm in the root site.
As you could guess, i have two questions:
- How to retreive blog info of another blog in the network, from the template of a blog?
- Why does
switch_to_blog(), followed by
restore_current_blog()makes the LOOP functions to behave incorrectly?
Thank you everyone! Have a great weekend!