很少见,但它必须按照您想要的运行方式进行默认设置。这将强制执行您需要的操作
function my_category_link( $termlink, $term_id ) {
$term = get_term( $term_id, \'category\' );
$ancestors = get_ancestors($term_id, \'category\');
if( !count($ancestors) ) return $termlink;
$hierarchical_slugs = array();
foreach ( (array)$ancestors as $ancestor ) {
$ancestor_term = get_term($ancestor, \'category\');
$hierarchical_slugs[] = $ancestor_term->slug;
}
$hierarchical_slugs[] = $term->slug;
return home_url( user_trailingslashit(implode(\'/\', $hierarchical_slugs), \'category\') )."\\n";
}
add_filter( \'category_link\', \'my_category_link\', 9, 2 );
要重组类别:
Assign parent category to all posts that are already assigned to child category