[wp-trac] [WordPress Trac] #48786: Wrong URLs to categories, authors etc. to a site in a multisite
WordPress Trac
noreply at wordpress.org
Mon Nov 25 01:41:48 UTC 2019
#48786: Wrong URLs to categories, authors etc. to a site in a multisite
--------------------------+-----------------------------
Reporter: Hinjiriyo | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Permalinks | Version: 5.3
Severity: normal | Keywords:
Focuses: multisite |
--------------------------+-----------------------------
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:
{{{#!php
<?php
$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 );
restore_current_blog();
}}}
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':
{{{https://www.example.com/de/blog/category/allgemein/}}}
which is wrong. The correct URL is
{{{https://www.example.com/de/kategorie/allgemein/}}}
On the german subsite the code prints this URL to the english category
'General':
{{{https://www.example.com/kategorie/general/}}}
which is wrong. The correct URL is
{{{https://www.example.com/blog/category/general/}}}
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:
{{{
get_author_posts_url()
get_category_link()
get_month_link()
get_post_format_link()
get_post_type_archive_link()
get_tag_link()
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/48786>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list