WordPress Custom Rewrite Rules
-
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:
https://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:
https://pastebin.com/PNHudKg5Currently, 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 https://example.com/courses/nc/charlotte, I get the correct match in the window below. So I know I’ve got something right.
- The topic ‘WordPress Custom Rewrite Rules’ is closed to new replies.