0

Disclaimer: I've had a look at quite a few similar questions and haven't found any that answer my question. If you think otherwise, kindly reply. :)


Alright, so I have one page: /classifieds/ What I'm aiming to do is route various link structures to a single page and handle the request in the page template.

These are the examples I'm trying to achieve:

example.com/classifieds/ - Page without any custom endpoints/rewrites

example.com/classifieds/hyundai-for-sale/ - Page that returns Hyundai results. I'm achieving this with the following rewrite rule.

add_rewrite_rule('^classifieds/([^/]*)-for-sale/?','index.php?page_id=839&make=$matches[1]','top');

example.com/classifieds/hyundai-for-sale/page/2/ - Page with pagination. I'm achieving this with the following rewrite rule.

add_rewrite_rule('^classifieds/([^/]*)-for-sale/page/([0-9]{1,})/?','index.php?page_id=839&make=$matches[1]&paged=$matches[2]','top');

example.com/classifieds/hyundai-for-sale/min-year/2014/max-year/2017/ - Page with any combination of "filters", including allowing them to stack into a long . All filters below, which I've been trying to create with endpoints with no success:

  • /classifieds/hyundai-for-sale/min-year/2014/
  • /classifieds/hyundai-for-sale/max-year/2017/
  • /classifieds/hyundai-for-sale/min-price/0/
  • /classifieds/hyundai-for-sale/max-price/12000/
  • /classifieds/hyundai-for-sale/min-mileage/0/
  • /classifieds/hyundai-for-sale/max-mileage/10000/
  • /classifieds/hyundai-for-sale/dealer/123456/
  • /classifieds/hyundai-for-sale/city/denver/state/colorado/
  • /classifieds/hyundai-for-sale/color/blue/
  • /classifieds/hyundai-for-sale/transmission/automatic/

What I mean by "Stackable endpoints"

  • /classifieds/hyundai-for-sale/max-price/12000/min-mileage/0/max-mileage/10000/dealer/123456/color/blue/

Hopefully there's a glaringly obvious answer I've just overlooked..

Any help would be greatly appreciated!

  • ok, so what is actually the question? ;) It seems like you should use CPTs and taxonomies, and for some parameters like price you are just trying to do things which just do not make much sense being part of a "permalink" – Mark Kaplun Apr 6 '17 at 7:29
  • I agree to @MarkKaplun, the question isn't clear actually. From the first sight, I would add a base prefix for all filter values to isolate all these parts of the URL, like: /classifieds/hyundai-for-sale/filter/../../../ Having this base allows you to intercept the request with any filter(s) and then just parse whatever goes after it and before pagination. – Ihor Vorotnov Apr 6 '17 at 9:56
  • Sorry if I wasn't clear enough in my original post. Unfortunately the way the data gets imported (4x daily) it doesn't make sense to use CPT's and taxonomies; also that doesn't allow "stackable" filters like what I'm after. The question is how do I achieve this? @IhorVorotnov 's comment may be the answer I'm looking for. – Austin Biggs Apr 8 '17 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.