Permalink displays incorrect URL when using switch_to_blog()
-
Permalink displays incorrect URL when using switch_to_blog()
I’m running WordPress MU 2.9.2 with multiple blogs setup as subdomains. I’m trying to display excerpts of posts from one blog (blog-A) onto another (blog-B). When I run through the loop, the links generated from functions like the_permalink(), the_category(), or comments_popup_link() display the URL path as though the post is generated from blog-B so when a user clicks on a link they are taken to a 404 page.
Here is the code I’m using:
<?php switch_to_blog($blog_id); ?> <?php query_posts("posts_per_page={$posts_per_page}&cat={$cat_id}"); ?> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <div class="date"><?php the_time('l, F jS, Y') ?></div> <?php the_post_thumbnail( 'blog-post' ); ?> <div class="entry"> <?php the_excerpt(); ?> </div> <div class="info"> <span class="category">Posted in <?php the_category(', ') ?></span> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?> </div> </div> <?php endwhile; ?> <?php endif; ?> <?php restore_current_blog(); ?>
The output of URLs generated is https://blog-b.example.com/xxxx/xx/xx/blog-title when they should be https://blog-a.example.com/xxxx/xx/xx/blog-title
Any idea what the problem might be?
- The topic ‘Permalink displays incorrect URL when using switch_to_blog()’ is closed to new replies.