WordPress.org

Make WordPress Core

Opened 23 months ago

Last modified 6 months ago

#20861 closed defect (bug)

switch_to_blog() breaks custom post type permalinks — at Initial Version

Reported by: sickhippie Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Multisite Keywords: close
Focuses: Cc:

Description

When using switch_to_blog() and custom post types, there are very strange results when calling the_permalink() or get_permalink(). For reference, we'll say the root site is blog1 and the second site containing the posts is blog2.

Using this code inside the loop:

switch_to_blog( $post->blog_id );
get_permalink();

If the post type is not registered on the current blog, the permalink given will be sitename.com/blog2/slug - when clicking it as href, it brings you the first instance of that slug in the database.

If the post type is registered on the current blog, the permalink given will be sitename.com/blog2/blog1/post-type/slug - this link will 404.

Related issue: 14992

Change History (0)

Note: See TracTickets for help on using tickets.