Opened 13 years ago
Closed 10 years ago
#21219 closed defect (bug) (wontfix)
get_post_type_archive_link in multisite context: struct issue
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Posts, Post Types | Keywords: | |
Focuses: | multisite | Cc: |
Description
Context : multisite and a site aaa ( http://localhost/wpmu_svn_34/aaa/ ) trying to display the post_type_archive_link of cpt 'book' of the blog bbb
switch_to_blog( $b ); $link = get_post_type_archive_link( 'book' ) ; /*/ http://localhost/wpmu_svn_34/bbb/book/ and not http://localhost/wpmu_svn_34/bbb/livre/ */ restore_current_blog();
when name, slug and query_var of the post_type are the same: no problem because $struct to find the '/book/' is kept from the caller site BUT
if in the called site, the CPT have the same type name ('book') but with different slug and query_var, the home_url is correctly changed but the $struct is not good... 'book' instead 'livre' as declared in cpt in site bob.
The issue came from global $wp_rewrite; which is not this of the target after the switch_to_blog !
Instead of a non elegant filter post_type_archive_link, is there a way to "find" the $wp_rewrite of $b ?
Best regards !
Change History (6)
#3
follow-up:
↓ 4
@
13 years ago
This issue is the same in get_post_permalink function (called by get_blog_permalink via get_permalink) which uses the global $wp_rewrite of the caller site and not this of the target site. today the workaround is to use the filter post_type_link.
#4
in reply to:
↑ 3
@
12 years ago
Replying to michelwppi:
today the workaround is to use the filter post_type_link.
I'm having this same issue.
Can you explain a bit more about how to use post_type_link?
#5
@
12 years ago
Thanks for your question.. in this code lines, you will find how to do
add_filter ('post_type_archive_link', 'switch_query_book', 10, 2); add_filter ('post_type_link', 'switch_query_book', 10, 2); function switch_query_book ( $link, $post_type) { global $blog_id; $link .= '#bid='.$blog_id; // here for test - comment if ok switch ( $blog_id ) { case 1 : $search = "livre"; $replace = "book"; break; case 2 : $search = "book"; $replace = "livre"; break; } $link = str_replace ($search, $replace, $link); return $link; }
Enjoy awaiting a better WP architecture with more separation !
#6
@
10 years ago
- Focuses multisite added
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to closed
I think a custom workaround here is the right solution. Generating rewrite rules for a site on switch_to_blog()
would involve too much overhead, though it is appealing. See also #20861, which is very related.
Global $wp_post_types seems to be also concerned through get_post_type_object