是的,这可以使用$wp->add\\u query\\u var函数和add\\u rewrite\\u规则一起使用。这里有一个例子:
Passing and retrieving query vars in wordpress
如果您需要更多帮助,请点击我的一个旧插件:
function createRewriteRules() {
global $wp_rewrite;
$new_rules = array(
\'(.?.+?)/(stenskott)$\' => \'index.php?pagename=\'.$wp_rewrite->preg_index(2).\'&ort=\'.
$wp_rewrite->preg_index(1),
\'(.?.+?)/(bilclas)$\' => \'index.php?pagename=\'.$wp_rewrite->preg_index(2).\'&ort=\'.
$wp_rewrite->preg_index(1),
\'(.?.+?)/(inbrott-i-bil)$\' => \'index.php?pagename=\'.$wp_rewrite->preg_index(2).\'&ort=\'.
$wp_rewrite->preg_index(1),
\'(.?.+?)/(om-glas)$\' => \'index.php?pagename=\'.$wp_rewrite->preg_index(2).\'&ort=\'.
$wp_rewrite->preg_index(1),
\'(.?.+?)/(kontakt)$\' => \'index.php?pagename=\'.$wp_rewrite->preg_index(2).\'&ort=\'.
$wp_rewrite->preg_index(1)
);
// Always add your rules to the top, to make sure your rules have priority
return $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
add_action(\'generate_rewrite_rules\', \'createRewriteRules\');
function query_vars($public_query_vars) {
$public_query_vars[] = "ort";
return $public_query_vars;
}
add_filter(\'query_vars\', \'query_vars\');
add_action(\'init\', \'add_endpoints\');
function add_endpoints()
{
add_rewrite_endpoint(\'ort\', EP_PAGES);
}