Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.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
Wordpress-以斜杠形式查询参数_Wordpress_Url_Url Rewriting_Query String - Fatal编程技术网

Wordpress-以斜杠形式查询参数

Wordpress-以斜杠形式查询参数,wordpress,url,url-rewriting,query-string,Wordpress,Url,Url Rewriting,Query String,我想将查询参数作为斜杠传递,而不是用“?”传递 e、 g.www.example.com/services?type=travel应转换为www.example.com/services/travel 在做了一些研究之后,我发现只有通过add\u rewrite\u rules才能实现。请看我迄今为止所做的尝试,但它不起作用 步骤1: // adding 'services_centers_type' as query variable function add_query_vars_filte

我想将查询参数作为斜杠传递,而不是用“?”传递

e、 g.
www.example.com/services?type=travel
应转换为
www.example.com/services/travel

在做了一些研究之后,我发现只有通过
add\u rewrite\u rules
才能实现。请看我迄今为止所做的尝试,
但它不起作用

步骤1:

// adding 'services_centers_type' as query variable
function add_query_vars_filter( $qvars ) {
    $qvars[] = 'services_centers_type';
    return $qvars;
}
add_filter( 'query_vars', 'add_query_vars_filter' );
步骤2:

// hook add_rewrite_rules function into rewrite_rules_array
function add_rewrite_rules($aRules) {
   $aNewRules = array('services/([^/]+)/?$' => 'index.php?pagename=services&services_centers_type=$matches[1]');
   $aRules = $aNewRules + $aRules;
   return $aRules;
}
add_filter('rewrite_rules_array', 'add_rewrite_rules');
步骤3:

// flush_rules() when adding new rules
add_filter('init','flushRules');
function flushRules(){
   global $wp_rewrite;
   $wp_rewrite->flush_rules();
}
第四步:
然后我转到后端,然后单击设置->永久链接&只需单击“保存更改”。

以上是我正在遵循的步骤,但不是为我工作。因此,当我转到
www.example.com/services/travel
时,它会将我重定向到
www.example.com/services/

请帮忙