0

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?

2 Answers 2

0

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.

0

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.

Your Answer

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

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