I’ve created my own search functionality which basically finds the nearest store closest to the entered postal code.
My URL for the search currently looks like this http://www.example.com/stores?searchTerm=London
, which is not really that SEO friendly. I would like my URL to be in the following format – http://www.example.com/stores/London
, however due to my lack of knowledge in how the WordPress URL Rewrites work I’m struggling with this and would like some help in resolving this issue.
Stores is a page that loops through the results.
If anybody has any ideas on how to do this or can point me in the right direction then it would be greatly appreciated.
You should add your own custom query variable first:
And then add rewrite rule:
You can then use
get_query_var('search_store');
to get search term.Just remember to flush rewrite rules, before you check it – it won’t work without flushing rules. (Just go to permalink settings and click save).
PS. Coded it directly in here, so it can be a little bit buggy.