好吧,我在这里解释我最终做了什么来解决这个问题。我还没有找到合适的方法,但是:
我创建了一个重写函数,用于检索所有参数并生成最终URL,其中的参数按特定方式排序。
function sc_change_programs_search_url_rewrite() {
if(get_query_var( \'post_type\' ) == \'program\') {
if(isset($_GET[\'word_search\']) || isset($_GET[\'os\']) || isset($_GET[\'category\']) || isset($_GET[\'archived\'])) {
$available_query_vars = array( \'word_search\' => \'p\', \'sistema_operatiu\' => \'so\', \'category\' => \'cat\', \'archived\' => \'archived\' );
$params_query = \'\';
foreach($available_query_vars as $query_var => $key) {
if (get_query_var( $query_var )) {
if($query_var == \'archived\') {
$params_query .= $key . \'/\';
} else {
$params_query .= $key . \'/\' . get_query_var( $query_var ) . \'/\';
}
}
}
if( ! empty( $params_query ) ) {
wp_redirect( home_url( "/programs/" ) . $params_query );
}
}
}
}
我创建了所有重写规则(考虑到顺序只能是一个,要实现的规则更少,但还是有很多):
$aNewRules = array(
\'programes/p/([^/]+)/so/([^/]+)/cat/([^/]+)/arxivats/?\' => \'index.php?post_type=programa&cerca=$matches[1]&sistema_operatiu=$matches[2]&categoria_programa=$matches[3]&arxivat=1\',
\'programes/p/([^/]+)/so/([^/]+)/cat/([^/]+)/?\' => \'index.php?post_type=programa&cerca=$matches[1]&sistema_operatiu=$matches[2]&categoria_programa=$matches[3]&arxivat=0\',
\'programes/p/([^/]+)/so/([^/]+)/arxivats/?\' => \'index.php?post_type=programa&cerca=$matches[1]&sistema_operatiu=$matches[2]&arxivat=1\',
\'programes/p/([^/]+)/cat/([^/]+)/arxivats/?\' => \'index.php?post_type=programa&cerca=$matches[1]&categoria_programa=$matches[2]&arxivat=1\',
\'programes/p/([^/]+)/so/([^/]+)/?\' => \'index.php?post_type=programa&cerca=$matches[1]&sistema_operatiu=$matches[2]&arxivat=0\',
\'programes/p/([^/]+)/cat/([^/]+)/?\' => \'index.php?post_type=programa&cerca=$matches[1]&categoria_programa=$matches[2]&arxivat=0\',
\'programes/p/([^/]+)/arxivats/?\' => \'index.php?post_type=programa&cerca=$matches[1]&arxivat=1\',
\'programes/p/([^/]+)/?\' => \'index.php?post_type=programa&cerca=$matches[1]&arxivat=0\',
\'programes/so/([^/]+)/cat/([^/]+)/arxivats/?\' => \'index.php?post_type=programa&sistema_operatiu=$matches[1]&categoria_programa=$matches[2]&arxivat=1\',
\'programes/so/([^/]+)/arxivats/?\' => \'index.php?post_type=programa&sistema_operatiu=$matches[1]&arxivat=1\',
\'programes/so/([^/]+)/cat/([^/]+)/?\' => \'index.php?post_type=programa&sistema_operatiu=$matches[1]&categoria_programa=$matches[2]&arxivat=0\',
\'programes/so/([^/]+)/?\' => \'index.php?post_type=programa&sistema_operatiu=$matches[1]\',
\'programes/cat/([^/]+)/arxivats/?\' => \'index.php?post_type=programa&categoria_programa=$matches[1]&arxivat=1\',
\'programes/cat/([^/]+)/?\' => \'index.php?post_type=programa&categoria_programa=$matches[1]\',
\'programes/arxivats/?\' => \'index.php?post_type=programa&arxivat=1\',
);
$aRules = $aNewRules + $aRules;
return $aRules;
仍然希望有更好的解决方案。。。