可以使用the_permalink 使用筛选和添加重写规则add_rewrite_rule 将新的永久链接重定向到标准post链接。
function mysite_modify_permalink($url) {
global $post;
//if taxonomy archive for Series get term
$term = is_tax(\'Series\')?get_query_var(\'term\'):\'\';
if(empty($term)) { //if no term was found
//get all Series terms for current post
$terms = get_the_terms($post, \'Series\');
//if terms were found, take first term found
if(!empty($terms) && is_array($terms)) $term = $terms[0]->slug;
}
//if term was found return a modified permalink url
//(replace last url segment starting from \'/\' with \'/<term slug><last segment>\')
if(!empty($term)) return preg_replace(\'#/blog(/[^/]+/?)$#\', \'/blog/\'.$term.\'$1\', $url);
//else return original url
else return $url;
}
add_filter(\'the_permalink\', \'mysite_modify_permalink\');
function mysite_add_rewrule() {
//get all Series terms
$terms = get_terms(array(\'taxonomy\' => \'Series\'));
//if terms were found, add a rewrite rule for urls containing one of them
if(!empty($terms) && is_array($terms)) {
foreach($terms as $key => $term) $terms[$key] = $term->slug;
$terms = \'(?:\' . implode(\'|\', $terms) . \')\';
add_rewrite_rule(\'^blog/\'.$terms.\'(/[^/]+/?)$\', \'index.php?name=$matches[1]\', \'top\');
}
}
add_action(\'init\', \'mysite_add_rewrule\');