I am trying to create a custom Rewrite URL something like
function add_my_rule() {
global $wp;
$wp->add_query_var('state');
$wp->add_query_var('state_destination');
add_rewrite_rule('destination/([0-9]+)/([^/]*)/page/([0-9]+)','index.php?pagename=destination&state=$matches[1]&state_destination=$matches[2]&paged=$matches[3]','top');
add_rewrite_rule('destination/([0-9]+)/([^/]*)','index.php?pagename=destination&state=$matches[1]&state_destination=$matches[2]','top');
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
add_action('init', 'add_my_rule');
Idea is to rewrite all URL which have following pattern
www.abc.com/destination/state/state-destination
I have a custom template destination.php and i want all such URL’s to be handled there.I have done same in past and that is working fine but now it does not seems working at all as for the given URL
http://localhost/xxx/destination/himachal-pradesh/dalhousie
it always going to single.php
and not to destination.php
.I tried to flush the cache and even browser one but seems like either my rewrite Rule is not correct or there is some other issue.
Any help in this will help me to move ahead.
As an added information my current URL-Structure in WordPress is /%year%/%monthnum%/%postname%.html
i am using WAMP Server with mode-rewrite enable.
this is a nice little re-write class created by: Author Kyle E Gentile
I found this a while back which works a treat in most plugins I’ve created…
Save the first section of code in a file called: add_rewrite_rules.php
Then include the file in your code to generate your new Re-Write rules..
that should be it, like I said I’ve used this a few times while building different plugins, I hope it works ok for you..
Marty