Wordpress删除URL中的父类别(域映射)
问题描述:
以下代码允许我删除我的主域邮件的父类别。 我的问题是,我使用第三方插件为了映射我的作者名称中的第二个域。Wordpress删除URL中的父类别(域映射)
- domain1.com 主域
- domain2.com MAPPED DOMAIN
永久链接结构:
- domain1.com/me/cat/subcat/postname = > domain2.com/cat/subcat/postname
所以基本上,domain1.com/me映射到domain2.com,它的工作好这样
,但如果我删除猫蛞蝓和只让SUBCAT像这样(用脚本):
- domain1.com/me/subcat/postname WORKING
- domain2.com/subcat/postname NOT WORKING(ERR_TOO_MANY_REDIRECTS)
脚本删除父塞在URL
add_filter('post_link', 'remove_parent_category', 10, 3);
function remove_parent_category($permalink, $post, $leavename)
{
$cats = get_the_category($post->ID);
if ($cats) {
usort($cats, '_usort_terms_by_ID');
$category = $cats[0]->slug;
if ($parent = $cats[0]->parent) {
// Find parent categories and replace them in the link
$parentcats = get_category_parents($parent, false, '/', true);
$permalink = str_replace($parentcats, '', $permalink);
}
}
return $permalink;
}