Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

As usual, rewrite stumped me! I've built a custom search for searching through comments and comment meta, using a flat table. I'm using a rewrite rule as follows:

..../search/reviews/<parameters>

I'm sending a query var 'args' which is group of key/val pairs to search against, to my custom template which has the sql and stuff. This works fine. My problem is, when I search as follows,

.../search/reviews/

Here I'm sending no params, hence I want to either redirect to 404 or just redirect to that same template with args as blank, where I'd see that args is blank and hence show all the results directly. I wrote the rule:

add_rewrite_rule('^search/reviews/','index.php?pagename=search-results','top');

But it still works as default search, searches for the keyword 'reviews' (like WP does for 'hello'.... /search/hello) and doesn't redirect to my template.

Any help on how to avoid this behavior?

share|improve this question
add comment

2 Answers

Have you tried:

add_rewrite_rule('^search/reviews/?','index.php?pagename=search-results','top');

instead? (Making the last / optional). If after flushing the rewrite rules that still doesn't work, check with Monkeyman rewrite analyzier and update the question with your findings.

share|improve this answer
add comment
up vote 0 down vote accepted

I used a jQuery trick to achieve this. I changed submit to a button and used jQuery to form the desired URL. If nothing was entered in the search form, then I redirected to the 404 URL.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.