Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php wordpress添加\重写\规则未导航到正确页面_Php_Wordpress - Fatal编程技术网

Php wordpress添加\重写\规则未导航到正确页面

Php wordpress添加\重写\规则未导航到正确页面,php,wordpress,Php,Wordpress,我需要将“”中的此url更改为“”,但它会导航到不正确的页面。任何帮助 我使用这个方法是为了重写url function events_custom_rewrite() { add_rewrite_rule("class-schedules/classCPA/?", 'index.php?page_id=4321&selectedCatId=52', 'top'); } 您还需要添加重写标记 请包含此代码并清除设置中的永久链接缓存 function custom_rewrite_tag

我需要将“”中的此url更改为“”,但它会导航到不正确的页面。任何帮助

我使用这个方法是为了重写url

function events_custom_rewrite() {
add_rewrite_rule("class-schedules/classCPA/?", 'index.php?page_id=4321&selectedCatId=52', 'top');
}

您还需要添加重写标记

请包含此代码并清除设置中的永久链接缓存

function custom_rewrite_tag() {
  add_rewrite_tag('%selectedCatId%', '([^&]+)');
}
add_action('init', 'custom_rewrite_tag', 10, 0);

function custom_rewrite_rule() {
    add_rewrite_rule('^class-schedules/classCPA/([^/]*)/([^/]*)/?','index.php?page_id=4321&selectedCatId=$matches[1]','top');
}
add_action('init', 'custom_rewrite_rule', 10, 0);
使用此代码,您应该(我没有测试它!)像这样访问您的站点:

global $wp_query;
$selectedCatId = $wp_query->query_vars['selectedCatId']; //52

在主题中,您可以访问如下变量:

global $wp_query;
$selectedCatId = $wp_query->query_vars['selectedCatId']; //52

重要提示:不要忘记刷新和重新生成重写规则 修改规则后的数据库。从WordPress管理屏幕, 选择Settings->Permalinks,只需单击SaveChanges(保存更改)而不进行任何更改 变化


您还需要
添加重写标记

请包含此代码并清除设置中的永久链接缓存

function custom_rewrite_tag() {
  add_rewrite_tag('%selectedCatId%', '([^&]+)');
}
add_action('init', 'custom_rewrite_tag', 10, 0);

function custom_rewrite_rule() {
    add_rewrite_rule('^class-schedules/classCPA/([^/]*)/([^/]*)/?','index.php?page_id=4321&selectedCatId=$matches[1]','top');
}
add_action('init', 'custom_rewrite_rule', 10, 0);
使用此代码,您应该(我没有测试它!)像这样访问您的站点:

global $wp_query;
$selectedCatId = $wp_query->query_vars['selectedCatId']; //52

在主题中,您可以访问如下变量:

global $wp_query;
$selectedCatId = $wp_query->query_vars['selectedCatId']; //52

重要提示:不要忘记刷新和重新生成重写规则 修改规则后的数据库。从WordPress管理屏幕, 选择Settings->Permalinks,只需单击SaveChanges(保存更改)而不进行任何更改 变化


页面不正确?或404页???@cgee其导航至4321页,但考虑到所选参数CATIDINcorrect页?或404页???@cgee将其导航到4321页,但考虑到参数selectedCatIdIMPORTANT:不要忘记在修改规则后刷新和重新生成重写规则数据库。在WordPress管理屏幕中,选择设置->永久链接,只需单击保存更改而不做任何更改。仍然面临相同的问题重要的是:修改规则后不要忘记刷新和重新生成重写规则数据库。在WordPress管理屏幕中,选择设置->永久链接,只需单击保存更改而不做任何更改。仍然面临相同的问题