[wp-trac] [WordPress Trac] #20861: switch_to_blog() breaks custom post type permalinks
WordPress Trac
noreply at wordpress.org
Tue Nov 6 12:35:31 UTC 2012
#20861: switch_to_blog() breaks custom post type permalinks
--------------------------+-----------------------
Reporter: sickhippie | Owner:
Type: defect (bug) | Status: reopened
Priority: normal | Milestone:
Component: Multisite | Version:
Severity: normal | Resolution:
Keywords: |
--------------------------+-----------------------
Changes (by jaroat):
* cc: jaroat (added)
* status: closed => reopened
* version: 3.3.2 =>
* resolution: worksforme =>
Comment:
Sorry - I can clearly reproduce that behaviour in a current (directory-
based) multisite-project:
'''As-Is State:'''
- WP 3.4.2
- Directory bases Multisite installation
- Custom Post Type "clipping" was registered in all blogs
- Actual clipping-entries lie in blog_id 2
- main blog address is "mydomain.tld/blog"
- blog 2 address is "mydomain.tld/verband"
'''home-template of main-blog:'''
{{{
switch_to_blog(2);
$clipping_id = get_id_from_some_function();
$clipping_url = get_permalink($clipping_id);
restore_current_blog();
}}}
'''Problem:'''
$clipping_url / permalink returned is:
http:// mydomain.tld /verband '''/blog''' /slug-of-post-type /slug-of-
clipping
I narrowed this down to the function get_extra_permastruct (wp-
includes/rewrite.php) called in function get_post_permalink (wp-includes
/link-template.php), which wrongly prepends "/blog" to all clipping slugs.
get_permalink does of course correctly work in templates of blog 2.
'''Wild assumption'''
Seems that get_extra_permastruct does not know that it has to act in the
context of blog 2 after using switch_to_blog.
br from Salzburg,
- Johannes
--
Ticket URL: <http://core.trac.wordpress.org/ticket/20861#comment:5>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list