Custom rewrite rule not translating into custom query vars
-
Hi guys, the following is actually making me some kind of a headache currently:
I have added some custom quer vars and those work fine so far:
function add_custom_query_vars($vars) { $vars[] = "tdhm"; $vars[] = "tdht"; return $vars; } add_filter('query_vars', 'add_custom_query_vars');
Then I added a custom rewrite rule
function add_rewrite_rules($aRules) { $aNewRules = array('tdh2015/danke/([^/]+)/([^/]+)/?$' => 'index.php?pagename=danke&tdhm=$matches[1]&tdht=$matches[2]'); $aRules = $aNewRules + $aRules; return $aRules; } add_filter('rewrite_rules_array', 'add_rewrite_rules');
And made sure, it was activated
$wp_rewrite->flush_rules( );
I then tested this rewrite rule with the monkeyman-rewrite-analyzer tool within wordpress and all looks fine so far. But when I try to access the variables within my custom page template, they never seem get populated.
actually the routing
“tdh2015/danke/myfirstparam/mysecondparam”
should translate to:
page: tdh2015/danke/
with the local variables
tdhm: myfirstparam
tdht: mysecondparamavailable. I tried to access the variables via
if(isset($wp_query->query_vars['tdhm'])) { $tdhm = urldecode($wp_query->query_vars['tdhm']); } if(isset($wp_query->query_vars['tdht'])) { $tdht = urldecode($wp_query->query_vars['tdht']); }
Has anyone here worked successfully with a similar setup?
Thanks in advance! Cheers, Matt
- The topic ‘Custom rewrite rule not translating into custom query vars’ is closed to new replies.