I’ve been looking for the answer to this everywhere but with no success and that’s why I’m asking here.
I don’t even know if the question is the right one.
In any case, I’ll try to explain.
I have a WordPress page with variables in the URL, like this: http://planeta-beisbol.com/tal-dia-como-hoy/?dia=18&mes=04
The content changes depending on the day and month of the year because is gathered from the databse.
My question is: How can I change the URL to look something like planeta-beisbol.com/tal-dia-como-hoy/dia/18/mes/04 or planeta-beisbol.com/tal-dia-como-hoy/18/04
Any help is apreciated. Thanks.
The following two functions should point you in the right direction:
I would give credit where it is due, but I cannot remember where I originally found this code. I just pulled this out of a project that I am currently working on. To use it, change
myvar
to the name of your variable in the first function as well as here:&myvar=$matches[1]
. Changepath/to/page/
to the actual path of your page at two locations in the second function.You can do you’re own custom permalink structures, have you looked here – http://codex.wordpress.org/Using_Permalinks?
Thanks to this post for the heads up: http://zagar.biz/2011/wordpress-creating-custom-permalinks/
My final code ended up being like this:
In the theme’s functions.php file
Then, in the page I created. This is just a regular wordpress page, not a template or anything like that
I have to edit the page to make it look good with my brand new permalinks.
This is the page I’ll using with this code: http://planeta-beisbol.com/tal-dia-como-hoy/19/04/
The “19/04” part means: 19th of April
I hope this code is useful for everybody