因此,在一位好朋友和php开发人员的帮助下,我自己就能够解决这个问题。很抱歉,有些功能i.e. CUSTOM::slugify()
是自定义的,但如有必要,您可以查看Div Starter theme 了解更多信息。
add_action( \'init\', \'cc_rewrite_add_rewrites\' );
function cc_rewrite_add_rewrites() {
$specialties = get_specialties(); //Fetches an array of postmeta defined from an ACF repeater field
add_rewrite_rule( "^(" . implode("|", array_map(function($a) { return strtolower(CUSTOM::slugify($a)); }, $specialties) ) . ")/?", \'index.php\', \'top\' );
flush_rewrite_rules();
// check path for specialty loop through specialties
foreach($specialties as $specialty) {
$slug = CUSTOM::slugify($specialty); // I needed to convert to a slug, custom function in Div Starter
if (preg_match("/\\/" . strtolower($slug) ."(\\/|$)/i", strtolower($_SERVER[\'REQUEST_URI\']) )) {
// set session variable
$_SESSION[\'specialty\'] = $specialty;
break;
}
}
}
我注意到我的分页使用了这种新的permalink结构,并将其破坏,因此我能够钩住它并删除添加内容,如下所示:
add_filter( \'get_pagenum_link\', \'wpse_cc_pagenum_link\' );
function wpse_cc_pagenum_link( $link ){
return $url = str_replace( \'/\'.CUSTOM::slugify($_SESSION[\'specialty\']), \'\', $link );
}
有关自定义永久链接的详细信息
this guide 真的很有帮助