I am developing a plugin, the goal of which is to allow for a bookmark-able, pretty permalink search engine on a single page. To do so, I am using WP's rewrite rules to allow for the searching/permalinks.

I need a structure as follows: http://example.com/courses/nc/charlotte Where /nc/ (or whatever is inputted/sent) would be accessible as a state variable later on, and the same for /charlotte/ as a city.

My code so far is as follows: http://pastebin.com/PNHudKg5 (updated to include suggested code from below, which did not stop the query vars from being stripped).

Currently, the echo '<h2>'.$course->post_title.'</h2>'; works as it is outputted before the rest of WP loads. However, if I move the code from the query parse function to a shortcode, the query params /nc/charlotte disappear off of the url and are inaccessible by my shortcode.

Am I missing some function that will keep the query parameters so I can use them on page? It seems like when the page loads, it strips the url, but before the page loads, they are still accessible.

Or maybe I'm doing it wrong altogether? I've found so many different ways of using WP's rewrite rules that my head is spinning. WP provides documentation on the functions, but not how to hook them all together to build something with them.

Also, I'm using Jan Fabry's Rewrite Analyzer plugin. When I type in http://example.com/courses/nc/charlotte, I get the correct match in the window below. So I know I've got something right.

Updated info: the shortcode was just a temporary means of executing code on the page. I actually need the page to utilize it's normal query in that it pulls the regular page content. The search results are supposed to be appended after the page content (hence the shortcode, or probably later - a page template).

Therefore, I cannot REPLACE the query, I am building a new one, and adding the matched posts to the page in the area designated (again, currently a shortcode in the content; later will be a page template).

My setup works awesome currently as I have it setup to use typical GET requests - like example.com/courses/?state=nc&city=charlotte

The above url gets posts with meta where custom fields (in this case, state and city) match the city and state in the GET request.

My goal is to move this functionality to WP Rewrite rules, like I mentioned above. Hope that makes it more clear.


1 Answer 1


Within your rewrite() method add:


That will keep the query_vars you added within the url, and prevent it from being stripped.

  • Thanks for the suggestion! I actually forgot to update the code in my question with that code. I already had that code (per a suggestion somewhere, I forgot where) in my plugin. Unfortunately, the query vars still get stripped... :/ Commented Mar 25, 2013 at 2:42

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.