在挖掘答案时this one, 我发现here 以下重写功能:
function eg_add_rewrite_rules() {
global $wp_rewrite;
$new_rules = array(
\'user/(profession|city)/(.+?)/(profession|city)/(.+?)/?$\' => \'index.php?post_type=eg_event&\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2) . \'&\' . $wp_rewrite->preg_index(3) . \'=\' . $wp_rewrite->preg_index(4),
\'user/(profession|city)/(.+)/?$\' => \'index.php?post_type=eg_event&\' . $wp_rewrite->preg_index(1) . \'=\' . $wp_rewrite->preg_index(2)
);
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
add_action( \'generate_rewrite_rules\', \'eg_add_rewrite_rules\' );
此函数采用如下url:example。com/user/profession/designer、knight/city/athens、gotham/并将其转换为变量:
$proffession = "designer,knight";
$city = "athens,gotham";
可以在分类法中使用。php
更多信息:https://stackoverflow.com/a/34624138/5594521
工作演示:http://playground.georgemanousarides.com/
希望有帮助!