The MU forums have moved to WordPress.org

restore_current_blog() Not Working as Anticipated (1 post)

  1. DragonFlyEye
    Member
    Posted 18 years ago #

    Not sure what's going on here, but clearly, restore_current_blog() is not working the way I had intended to use it. Based on what I've read in other functions in wpmu-functions.php, it should be a simple question of using switch_to_blog() to go mess with another blog, then restore_current_blog() should bring you back where you were. Sadly, that's not happening. Here's my code:

    foreach ($blogs as $blog) {
            	if (!in_array($blog['blog_id'], $ignore)) {
            		switch_to_blog($blog['blog_id']);
            		$latest = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND post_date < NOW() ORDER BY post_date DESC", ARRAY_A);
            		$auth = $latest['post_author'];
            		$latest['post_author'] = $wpdb->get_var("SELECT user_email FROM wp_users WHERE ID = $auth");
            		$words = explode(' ', strip_tags($latest['post_content'], '<br>,<p>'));
            		$tease = '';
            		for($x=0; $x<80; $x++) {
            			$tease .= $words[$x].' ';
            		}
            		$latest['post_content'] = $tease;
            		$latest['post_link'] = get_blog_permalink($blog['blog_id'], $latest['post_id']);
            		if(function_exists(feature_art_gravatar)) { $latest['gravatar'] = feature_art_gravatar($latest['post_author'], 'PG', 80, 'http://dragonflyeye.net/allsorts/default_avatar_48.png'); }
            		$posts[] = $latest;
            	}
            }

    It's definitely switching blogs with switch_to_blog just fine, but the switching back part isn't working. Also, for some reason, the get_blog_permalink function isn't working, either.

    Anybody have any ideas?

About this Topic

  • Started 18 years ago by DragonFlyEye