Support » Fixing WordPress » 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_States

    Or consider a user-friendly crafting of a search query for a product:
    /products/manufacturer_name/blue/metal/new/sports
    /products/new/plastic/red/manufacturer_name

    I 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.

    • This topic was modified 1 year, 7 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    All that really matters for getting to a specific object is its slug in the URL. The additional parameters don’t really matter, as long as they are valid. The object’s slug can appear where you like in an URL, but it really should be in a predictable position. The very last position is often used for object slugs for this reason.

    If the slug’s position is unknown, you’d have to try to find an object matching any one of the URL elements. If only the actual slug results in a hit, it’s all good. But if there are multiple hits, how is the parser supposed to know which is the real requested slug? If all the other elements are known to be terms of a taxonomy, they could be included in the query to increase the chances of resolving any ambiguity. It would also increase the chances of finding no match at all if any of the terms are off in the lest bit.

    In any case, the need to pre-query to verify we’re using the right slug increases the burden on the DB engine. It’s entirely unnecessary if the slug is always in a predictable position. Then we can simply query for the slug directly and get on with serving the request.

Viewing 1 replies (of 1 total)
  • The topic ‘Flow from URL to plugin to post?’ is closed to new replies.