[wp-trac] [WordPress Trac] #38305: wrong permalink structure return by get_permalink() when switching blog in WPMU

WordPress Trac noreply at wordpress.org
Tue Nov 22 11:49:47 UTC 2016


#38305: wrong permalink structure return by get_permalink() when switching blog in
WPMU
--------------------------------+------------------------------
 Reporter:  5um17               |       Owner:
     Type:  defect (bug)        |      Status:  new
 Priority:  normal              |   Milestone:  Awaiting Review
Component:  Networks and Sites  |     Version:
 Severity:  normal              |  Resolution:
 Keywords:  close 2nd-opinion   |     Focuses:  multisite
--------------------------------+------------------------------

Comment (by nikosnikos):

 I have the same problem, I have three sites in my network : Site 1 in
 french, site 2 in spanish and site 3 in english.

 I want to display in french and spanish sites a list of english categories
 (child of "latest news" english site category).
 I modified the category base in permalink settings so in french site it is
 "actualites", in spanish it is "actualidad", in english it is not
 modified.

 In my template :
 {{{#!php
 <?php
 switch_to_blog(3);
 $english_news_cat = get_term_by('slug', 'latest-news', 'category');
 $english_news_cat_list = wp_list_categories(array('child_of' =>
 $english_news_cat->term_id, 'hide_empty' => false, 'echo' => false,
 'title_li' => 'News in english'));
 restore_current_blog();
 }}}

 In my functions.php, I have to write a hack to get this work :
 {{{#!php
 <?php
 add_filter('category_link', 'ticket38305_category_link_hack');
 function ticket38305_category_link_hack( $termlink ) {
   global $switched;
   if ($switched && 3 == get_current_blog_id()) {
     // Ugly preg_replace
     $cat_permalnk = array(1 => 'actualites', 2 => 'actualidad');
     $termlink =
 preg_replace('#^('.home_url().'/)'.$cat_permalnk[$GLOBALS['_wp_switched_stack'][0]].'(/.*)$#',
 '$1category$2', $termlink);
   }
   return $termlink;
 }

 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/38305#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list