也许您需要添加自己的query\\u var来获得工作
// Add query_var
function add_question_var($question_vars) {
$question_vars[] = \'ed\';
return $question_vars;
}
//add a rewrite rule
function do_rewrite_question() {
global $wp_rewrite;
add_rewrite_rule(\'question/ask/?$\', \'index.php?pagename=ask\',\'top\');
add_rewrite_rule(\'question/ed/(.+)/?$\', \'index.php?pagename=question&ed=$matches[1]\',\'top\');
}
function template_redirect_file()
{
global $wp_query;
if ( get_query_var(\'pagename\')==\'ask\')
{
// Do your stuff
}
if ( $wp_query->get(\'ed\'))
{
// Do your stuff
}
}
// redirect_canonical
function noredir($redirect_url)
{
$vars = array (
\'ed\' => get_query_var(\'ed\'),
);
if (!empty($vars))
return false;
}
add_filter(\'query_vars\', \'add_question_var\');
add_action(\'init\', \'do_rewrite_question\');
add_action(\'template_redirect\', \'template_redirect_file\');
add_filter(\'redirect_canonical\', \'noredir\');
那你应该
update the permalink 通过wp admin/options permalink。phpto测试重写工作,将此代码添加到
add-question.php<?php
if(isset($wp_query->query_vars[\'pagename\'])) {
echo urldecode($wp_query->query_vars[\'pagename\']);
}
?>
并且在
edit-question.php<?php
if(isset($wp_query->query_vars[\'ed\'])) {
echo urldecode($wp_query->query_vars[\'ed\']);
}
?>