好吧,伙计,我从未使用过add_rewrite_rule
,WP codex 说是It is most commonly used in conjunction with add_rewrite_tag()
。
因此,我只是向您展示退伍军人在过去是如何重写规则的。
但此外,如果您正在为大众构建插件,则必须避免使用WP 3.5 features
很多人仍在使用 WP2.*。
这组操作可以帮助您:
add_action('init', 'flushRewriteRules');
function flushRewriteRules()
{
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
add_filter('rewrite_rules_array', 'insertMyRewriteRules');
function insertMyRewriteRules($rules)
{
$newrules['^episodes/([^/]*)/([^/]*)/?$'] = 'index.php?post_type=episodes&seasons=$matches[1]&episodes=$matches[2]';
return $newrules + $rules;
}
add_filter('query_vars', 'insertMyRewriteQueryVars');
function insertMyRewriteQueryVars($vars)
{
array_push($vars, 'episodes', 'seasons', 'post_type');
return $vars;
}