0

I am trying to rewrite a query string in Wordpress within the functions.php file, but it just isn't working. I'm probably making some dumb mistake, so any guidance is greatly appreciated!

I am trying to rewrite this URL: www.domain.com/car-lease-rate/?term1=true to www.domain.com/car-lease-rate/term1... or if possible www.domain.com/car-lease-rate/term/1.

add_action('init', 'add_my_rewrite');
function add_my_rewrite() {
    add_rewrite_rule('^car-lease-rate/term/([^/]+)','index.php?term1=$matches[1]','top');
}
3
  • I don't have very much experience with Wordpress. But I see in admin dashboard, there is a section to config permalinks. You can see here codex.wordpress.org/Using_Permalinks Commented Jan 16, 2015 at 2:34
  • @MinhQuý It will rewrite posts, pages, tags, categories, ect. But nothing beyond that (as far as I know). The add_rewrite_rule function exists to cover that, but I just can't get the regular expression to work! Commented Jan 16, 2015 at 2:38
  • Rewrites is still a bit of a mistery for me, on tip I can give you though, remember, you have to flush your rewrites after every change for them to take affect Commented Jan 16, 2015 at 8:30

1 Answer 1

1

You can try my code. I don't test it :p

add_action('init', 'add_my_rewrite');
function add_my_rewrite() {
    add_rewrite_rule('^car-lease-rate/term1/([^/]*)/?','index.php/car-lease-rate?term1=$matches[1]','top');
}
Sign up to request clarification or add additional context in comments.

1 Comment

So sad! This's first times I code with Wordpress so I can't help you. Here's document codex.wordpress.org/Rewrite_API/add_rewrite_rule that I read

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.