Dynamic URL Routing
-
Based on the path, I’m able to write custom routes to get the correct page, and set some custom variables… for example:
If the route takes a URL in this format:
https://example.com/products/:product_name
And we hit this URL:
https://example.com/products/baseball-glove
And we’re able to retrieve the page by doing:
get_page_by_path('products/product');
Right now, the original query initially searches for
products/baseball-glove
which returns theWP_Post
object for404 / Page Not Found
, even though my subsequent query withget_page_by_path
gets me the correctWP_Post
object. How can I reset the global$post
object to overwrite the currentWP_Post
and so that other plugins are able to use functions like thethe_title()
?
- The topic ‘Dynamic URL Routing’ is closed to new replies.