Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Show Posts from another blog on WordPress MU Website WordPress

I found this function that is supposed to do what I'm looking for:

function show_blog_posts( $_blog_id ){
global $wpdb, $table_prefix, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache;
if( !$wpdb->get_var( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE blog_id = %s" ), $_blog_id ))
return;
switch_to_blog( $_blog_id );
query_posts(array('post_type'=>'post','post_status'=>'publish','showposts'=>'5'));
if( have_posts()):
echo '<ol>';
while(have_posts()): the_post();
echo sprintf( '<li><a href="%1$s">%2$s</a></li>', get_permalink(), get_the_title());
endwhile;
echo '</ol>';
endif;
wp_reset_query();
restore_current_blog();
}


Calling this function anywhere in the theme with a snippet like this :

<?php show_blog_posts( '5')?>

should return a list of the last 5 posts from blog with ID 5, but apparently it's not working...

is the function broken or I'm missing something?

Answers (4)

2011-08-01

Romel Apuya answers:

are you using this inside a have post loop?

2011-08-02

Reland Pigte answers:

Hi Gino,

function show_blog_posts( $blog_id ) {
$blog_details = get_blog_details($blog_id);
if($blog_details):
switch_to_blog( $_blog_id );
query_posts(array('post_type'=>'post','post_status'=>'publish','showposts'=>'5'));
if( have_posts()):
echo '<ol>';
while(have_posts()): the_post();
echo sprintf( '<li><a href="%1$s">%2$s</a></li>', get_permalink(), get_the_title());
endwhile;
echo '</ol>';
endif;
else:
echo 'No posts found on this blog!';
endif;
wp_reset_query();
restore_current_blog();
}


try this code, add this to your function.php

Hope this will work, happy coding..


Reland Pigte comments:

or this

function show_blog_posts( $blog_id ) {
$blog_details = get_blog_details($blog_id);
if($blog_details):
switch_to_blog( $_blog_id );
query_posts(array('post_type'=>'post','post_status'=>'publish','showposts'=>'5'));
if( have_posts()):
echo '<ol>';
while(have_posts()): the_post();
echo sprintf( '<li><a href="%1$s">%2$s</a></li>', get_permalink(), get_the_title());
endwhile;
echo '</ol>';
endif;
restore_current_blog();
wp_reset_query();
else:
echo 'No posts found on this blog!';
endif;
}

2011-08-02

Graham Kite answers:

If you go to the tools in the area of the site you are wanting to get the posts from you can export them all. and then go to the tools in the admin area of the site you want them in and import.

you can export/import, whole site or posts or pages. would think that would be quickest, cheapest and easiest

2011-08-02

Sébastien | French WordpressDesigner answers:

i have a function that do what you want

if you write <?php show_blog_posts(48) ?> the 5 latest posts of the site 48 are displayed.
Exactly like the function you use, and that work !

Increase your fee please to 20$ and i post that here