我在网上找到了我的答案。
function numeric_category_rewrite_rules( $rules ) {
$custom_rules = array();
foreach ( $rules as $regex => $rewrite ) {
$regex = str_replace( \'/(.+?)/\', \'/([0-9]{1,})/\', $regex );
$rewrite = str_replace( \'?category_name=\', \'?cat=\', $rewrite );
$custom_rules[ $regex ] = $rewrite;
}
return $custom_rules;
}
add_filter( \'category_rewrite_rules\', \'numeric_category_rewrite_rules\' );
function numeric_category_link( $category_link, $term_id ) {
global $wp_rewrite;
if ( $wp_rewrite->using_permalinks() ) {
$permastruct = $wp_rewrite->get_extra_permastruct( \'category\' );
$permastruct = str_replace( \'%category%\', $term_id, $permastruct );
$category_link = home_url( user_trailingslashit( $permastruct, \'category\' ) );
}
return $category_link;
}
add_filter( \'category_link\', \'numeric_category_link\', 10, 2 );