Make WordPress Core

Opened 5 years ago

Last modified 16 months ago

#48786 new defect (bug)

Wrong URLs to categories, authors etc. to a site in a multisite

Reported by: hinjiriyo's profile Hinjiriyo Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.3
Component: Permalinks Keywords:
Focuses: multisite Cc:


WP returns a wrong URL to a term if the term is in another site of a multisite. Terms like categories, tags, authors, date archives and other terms.

How to reproduce: execute this code, with site ID and post ID as examples of valid values in the current installation, in a subsite different to site ID = 3:

$site_id = 3;
$post_id = 1389;
$category_links = array();

switch_to_blog( $site_id );
$categories = get_the_terms( $post_id, 'category' );
foreach ( $categories as $category ) {
        // get link to category
        $category_links[] = sprintf(
                '<a href="%s">%s</a>',
                esc_url( get_category_link( $category->term_id ) ),
                esc_html( $category->name )
print join( ', ', $category_links );

If other base names for the category and tags are used (being specified on the Permalinks Settings page) the bug is more obviuos. In the next example the subsite is the german version of the main site, so the site path is '/de' and the category base name is specified to 'kategorien', and the german name for the category 'General' is 'Allgemein':

On the english main site the code prints this URL to the german category 'Allgemein':
which is wrong. The correct URL is

On the german subsite the code prints this URL to the english category 'General':
which is wrong. The correct URL is

The code sets correct links if it is executed in the site with the ID = 3 (e.g. is current site is same as the site being switched to).

Same is with similar functions like:


Change History (1)

#1 @timholz
16 months ago

I encounter the same mix-up for the category base:

if (is_archive() && !is_tag()){
    switch_to_blog($myblog_id );
    //get category link of switched blog
    $url_cat = get_category_link(get_query_var( 'cat' ));
    echo $url_cat;

The echo for $myblog_id = 1 is:

http://localhost/es/category/archivo/ //should be categoria

The echo for $myblog_id = 2 is:

http://localhost/categoria/archiv/ //should be category

The same counts for get_tag_link()

Last edited 16 months ago by timholz (previous) (diff)
Note: See TracTickets for help on using tickets.