I have followed the WordPress tutorial for this, but I can’t get it to work.
http://codex.wordpress.org/Rewrite_API/add_rewrite_rule
What I have now:
http://domain.com/timezone?country=netherlands&city=amsterdam
What I want to achieve
When I go to that URL now I get redirected back to http://domain.com/timezone
I added this code to the functions.php
function custom_rewrite_tag() {
add_rewrite_tag('%country%', '([^&]+)');
add_rewrite_tag('%city%', '([^&]+)');
}
add_action('init', 'custom_rewrite_tag', 10, 0);
function custom_rewrite_rule() {
add_rewrite_rule('timezone/([^/]*)/([^/]*)','index.php?page_id=4&country=$matches[1]&city=$matches[2]','top');
}
add_action('init', 'custom_rewrite_rule', 10, 0);
?>
and this code to my custom template
global $wp_query;
echo 'country : ' . $wp_query->query_vars['country'];
echo '<br />';
echo 'city : ' . $wp_query->query_vars['city'];
?>
Am I missing something?
Can someone please help?????