I want to want to make url friendly urls for a custom function I am using in my website. I have added a custom template on my theme dir.
The url rewrite function that looks like this:
function starts_rewrite_rule() {
add_rewrite_rule('^cities-starting-with-([^/]*)/?','index.php?page_id=340&start_letter=$matches[1]','top');
}
add_action('init', 'starts_rewrite_rule', 10, 0);
The url becomes:
site.com/cities-starting-with-a/
All good and the parameters are read properly from the function. And when the accessed permalink changes to
site.com/cities-starting-with-pa/
the sql query changes to "ab".
After I update the Permalinks ( click save on permalinks ). I wanted to extend the functionality and add another url rewrite rule. I added a higher priority because the url patter was identical (except the new url reweire rule had an extra parameter. SO I copy paste the same function and add the extra parameter.
function x_letter_cities_starts_rewrite_rule() {
add_rewrite_rule('^([^/]*)-letter-words-starting-with-([^/]*)/?','index.php?page_id=340&length=$matches[1]&start_letter=$matches[2]','top');
}
add_action('init', 'x_letter_cities_starts_rewrite_rule', 14, 0);
The url is supposed to become: site.com/7-number-cities-starting-with-pa/
But it seems like wordpresses rewrite function cant properly detect the extra parameter (7),. so the results are the same as the url that is accessed like:site.com/cities-starting-with-pa/
It seems like the priority is not working correctly. OR url rewrite rule IGNORES the first part "7-number-" and only reads the second part pattern of the url "cities-starting-with-pa/", because they end in the same pattern.
Can anyone help me in this tricky situation. I appreciate your help/clues/ideas.
Thank you, shoku i petrit.