Query parameters as slash
-
I want to pass a Query parameters as slash not with the ‘?’.
e.g.
should be converted to
.
After doing some research, I have found out that it can be achieved only with
add_rewrite_rules
. Please see what I have tried till now, but it is not working.
Step1:
// 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' );
Step2:
// 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');
Step3:
// flush_rules() when adding new rules add_filter('init','flushRules'); function flushRules(){ global $wp_rewrite; $wp_rewrite->flush_rules(); }
Step4:
Then I go to the backend then then click on the Settings->Permalinks & just click on the 'Save changes'.
Above are the steps I am following, but not working for me. So when I go to
, it redirects me to
.
Please help!
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘Query parameters as slash’ is closed to new replies.