Flow from URL to plugin to post?
-
I’m looking for guidance and links about how to approach what seems to be a common challenge. I want path a/b/c/d/* to ultimately go to a post, but I’m not sure if the approach is to use permalinks, rewrite, or some other mechanism.
The URL will be parsed on slashes and the post identified by the data. In this case, the URL might be a/b/c/d, a/b/d, even d/c/b/a, and given the detail I know how to drill into the final post.
As a practical example, consider that all of these should resolve down to the same ‘city’ record:
/location/usa/illinois/chicago
/location/illinois/chicago (if logged-in user is in USA)
/location/chicago (there’s only one)
/location/Chicago/Illinois/United_StatesOr consider a user-friendly crafting of a search query for a product:
/products/manufacturer_name/blue/metal/new/sports
/products/new/plastic/red/manufacturer_nameI do not want to follow a common pattern like /taxonomy/slug, or /yy/mm/dd. I have no idea what combinations of terms will be used or in what order.
I do not want to encode a fixed structure that results in rigid rewrite rules. For example: /text/([^/]+)/ > index.php?foo=$matches[1]&bar=$matches[2]…
Maybe the rewrite would be /location/(.*) > index.php?wholepath=$matches[1] ?
Or maybe I should catch a 404 after all other processes have had their shot at it, and see if it fits a pattern without starting with a keyword? That seems wasteful.
I’m also adverse to creating child pages for every combination because that’s just a ton of potentially unused data waiting for a hit. In the above example, if “chicago” is recognized then all other queries will be limited to that scope – I don’t need a record with slug “chicago” – though there might be one.
The issue is that I don’t know if I should create a rewrite, or maybe parse $_SERVER[‘REQUEST_URI’] from ‘init’ or somewhere else and then redirect. Am I describing multiple permalinks per CPT?
Again, I want to understand flow and approaches so that I (and others) know how to approach similar challenges in the future. I don’t just want an answer to a single challenge because then I’ll just the same question for the next challenge. The interwebs are full of Q&A on this topic but the answers and blogs that I’ve found are all very specific solutions to specific challenges, and not about general flow and options. I’ll keep looking.
Kind thanks.
- The topic ‘Flow from URL to plugin to post?’ is closed to new replies.