0

I have a WPMU installation wherein the primary site contains all of the posts (over 60,000) and the sub-sites, all with separate domain names, fetch the post content using the switch_to_blog() function and perform a translation function upon them before displaying. The sub-sites have NO posts themselves, and, owing to the large quantity of posts, it is impractical to just copy them. The problem is with the sub-sites' RSS feeds. It seems that switch_to_blog(1) doesn't work within the loop in a feed template. What I have done is disable the native WP feeds with a plugin and added custom templates within the plugin folder (copying template files feed-rss2.php and feed-rss2-comments.php from WordPress core). WP is correctly using the template files and I have tried switch_to_blog(1) in various places in the template file (it needs to be AFTER the <channel>...</channel> information, which is obtained from the sub-site meta information).

Plugin code:

remove_all_actions( 'do_feed_rss2' );
function prefix_do_feed_rss2( $for_comments ) {
if ( $for_comments )
    load_template( plugin_dir_path( __FILE__ ) . 'feed-rss2-comments.php' );  //copied from WP core
else
    load_template( plugin_dir_path( __FILE__ ) . 'feed-rss2.php' );   //copied from WP core
}
add_action( 'do_feed_rss2', 'prefix_do_feed_rss2' );`

The most likely spot is at the beginning of the loop (modified WP core template file feed-rss2.php), thus:

do_action( 'rss2_head' );
             switch_to_blog(1);  //<---ONLY LINE ADDED
while ( have_posts() ) :
    the_post();
    ?>
<item>
    <title><?php the_title_rss(); ?></title>...

but this does not seem to work. Since the sub-site has no posts, nothing else is displayed, just the closing </rss> tag. Any suggestions would be appreciated!

Thanks!

-Brian Brown, Ph.D.

"Geeking Since 1962!"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.