Custom Rewrite Rules – query_vars issue
-
I have create the following function that is hooked on init action, in order to add my custom re-write rules:
public function customRewriteRules() { add_rewrite_tag('%specialty%', '([^/]+)', 'specialty='); add_rewrite_tag('%region%', '([^/]+)', 'region='); add_rewrite_tag('%lngg%', '([^/]+)', 'lngg='); add_rewrite_tag('%zpcd%', '([^/]+)', 'zpcd='); add_rewrite_tag('%find%', '([1])', 'find='); add_rewrite_rule( '^find/([^/]+)/([^/]+)/([^/]+)/?$', 'index.php?find=1&specialty=$matches[1]®ion=$matches[2]&s=$matches[3]', 'top' ); add_rewrite_rule( '^find/([^/]+)/([^/]+)/([^/]+)/page/([0-9]+)/?$', 'index.php? find=1&specialty=$matches[1]®ion=$matches[2]&s=$matches[3]&page=$matches[4]', 'top' ); add_rewrite_rule( '^find/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$', 'index.php?find=1&specialty=$matches[1]®ion=$matches[2]&s=$matches[3]&lngg=$matches[4]&zpcd=$matches[5]', 'top' ); add_rewrite_rule( '^find/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/page/([0-9]+)/?$', 'index.php?find=1&specialty=$matches[1]®ion=$matches[2]&s=$matches[3]&lngg=$matches[4]&zpcd=$matches[5]&page=$matches[6]', 'top' ); if(get_option('x_rewrite_added', 0) == 0) { update_option('x_rewrite_added', 1); flush_rewrite_rules(); } }
When I try the URL
https://www.mysite.com/find/someterm/someterm/somesearch/
I get the following query_vars
[query_vars] => Array ( [s] => none [region] => someterm [specialty] => someterm )
and the following query_string
s=none®ion=someterm&specialty=someterm
When I try the URL
https://www.mysite.com/find/someterm/someterm/somesearch/page/4
I get the following query_vars
[query_vars] => Array ( [s] => none [page] => 4 [region] => someterm [specialty] => someterm )
and the following query_string
s=none&page=4®ion=someterm&specialty=someterm
But when I try to enter the following URL:
https://www.mysite.com/find/someterm/someterm/somesearch/someterm/someterm/
I am getting the following query_vars
[query_vars] => Array ( [s] => none [region] => someterm [specialty] => someterm )
and the following query_string
s=none®ion=someterm&specialty=someterm
as weill when I try the
https://www.mysite.com/find/someterm/someterm/somesearch/someterm/someterm/page/2
I am getting the following query_vars
[query_vars] => Array ( [s] => none [page] => 2 [region] => someterm [specialty] => someterm )
and the following query_string
s=none&page=2®ion=someterm&specialty=someterm
- The topic ‘Custom Rewrite Rules – query_vars issue’ is closed to new replies.