The MU forums have moved to WordPress.org

2.6rc1: Problem with switch_to_blog? (13 posts)

  1. DragonFlyEye
    Member
    Posted 16 years ago #

    Note this code:

    function main_pages() {
    	global $wpdb, $blog_id;
    
    	switch_to_blog(1);
    		$pages = get_posts('post_type=page&exclude=50,77');
    		foreach($pages as $page) {
    			$link = get_permalink($page->ID);
    			?><li><a href="<?php echo($link); ?>"><?php echo($page->post_title); ?></a></li><?php
    		}
    	restore_current_blog();
    }

    That should list out pages from the home blog on any other blog. However, the permalinks are coming out referencing the current blog. See this page, top navigation, for reference:

    http://holisticnetworking.net/aquarist/

    Those links should be "http://holisticnetworking/portfolio," not "http://holisticnetworking.net/aquarist/portfolio."

    Whatup with that?

  2. tdjcbe
    Member
    Posted 16 years ago #

    Beats me to be honest but why not just add it the url as hard code and say the heck with it? :)

    <li><a href="http://holisticnetworking/<?php echo($link); ?>">

  3. DragonFlyEye
    Member
    Posted 16 years ago #

    Because the permalink may not always be the same as what it is in the database.

  4. MrBrian
    Member
    Posted 16 years ago #

    After switch_to_blog why don't you echo $blog_id to see if the blog id has actually changed.

  5. dsader
    Member
    Posted 16 years ago #

    DragonFlyEye, you are right, I see the same bug.

    MrBrian, the correct $blog_id is echoed but the correct links are not returned.

  6. DragonFlyEye
    Member
    Posted 16 years ago #

    Yeah, the only place I've seen this issue crop up so far has been the combination of switch_to_blog() and get_permalink(). Seems like something must be a little wacky about the $wpdb object, but I haven't had a chance to look too far into it because I'm still working on my login issues.

  7. lunabyte
    Member
    Posted 16 years ago #

    Have you printed back the wpdb object, to see if it was actually rolled over in the database?

    Have you checked changes to get_permalink from 1.5.1 to the 2.6rc?

  8. DragonFlyEye
    Member
    Posted 16 years ago #

    luna~ That's a no on both counts. I'll be playing around more with this later today.

  9. DragonFlyEye
    Member
    Posted 16 years ago #

    Looks like my two problems are converging on the same point:
    http://mu.wordpress.org/forums/topic.php?id=8900

    See the bottom where I lay out the problem with both my cookies and $wpdb. I think we're looking at the same bug.

  10. donncha
    Key Master
    Posted 16 years ago #

    I'm not sure the two bugs are related, but I did find a bug in the switching code because the generic cache class doesn't know about blog_ids. It's now fixed in trunk if you want to try that.
    Grab the zip file from http://trac.mu.wordpress.org/browser/trunk and copy over the files of your install.

  11. DragonFlyEye
    Member
    Posted 16 years ago #

    Thanks, Donncha! I'll give this a shot when I get back to the homestead.

  12. konus
    Member
    Posted 16 years ago #

    Upgrading to the current trunk help me too!!! Thanks!

  13. konus
    Member
    Posted 16 years ago #

    Doesn't work anymore... =( (trunk either)

About this Topic

  • Started 16 years ago by DragonFlyEye
  • Latest reply from konus