I am now passing parameters to a custom template in the following format
www.example.com/?pageid=12&rid=24&title=this-is-the-title
I have created two tables . So I need to fetch data and display them on those pages.
I would like it to be using clean URL format like:
www.example.com/pageid/12/rid/24/title/this-is-the-title
Can anyone tell how this can be achieved?
Thanks
add_rewrite_rule()
allows you to turn the pretty url into variables.(d*)
/rid/
or/pageid/
([a-zA-Z0-9-]+
Here is a class to register the rewrite and handle the request if a match has been found.
UPDATE
I found a simpler way to handle this.
http://example.com/pageid/333/rid/444/title/your-title-here/
This new way utilizes
add_rewrite_tag
with_
to run the query for a page’s ID without messing up the main query. In the example above,333
would just modify the query to look for that post ID inpre_get_posts
. You could just as easily modifytemplate_redirect
ortemplate_include
.To reference all the params passed later:
REFERENCE
If you want a simple solution this might be it (haven’t tested the code so might not be so simple if it’s not working…) or atleast it give some hint what you need to do. If you visit http://thereforei.am/2011/10/28/advanced-taxonomy-queries-with-pretty-urls/ you will find a bonus prize: A Rewrite Rule Generator in the article. I have used this before but not in a situation exactly like this. Try to combine that function with something like this:
If you don’t want to use the eg_generate_rewrite_rules function, you need to set up the rules yourself. You can find information on how to do that in that article.
More info:
http://codex.wordpress.org/Rewrite_API/add_rewrite_tag