I'm building an advanced search form and having some difficulty with getting the results. The form inputs include price and year ranges. For example, search for used cars from $10,000 to $20,000.
The search is working, here's my results page code:
{% set manufacturer = craft.request.getParam('manufacturer') %}
{% set model = craft.request.getParam('model') %}
{% set bodyStyle = craft.request.getParam('bodyStyle') %}
{% set minPrice = craft.request.getParam('minPrice') %}
{% set maxPrice = craft.request.getParam('maxPrice') %}
{% set startYear = craft.request.getParam('startYear') %}
{% set endYear = craft.request.getParam('endYear') %}
{% set results = craft.entries.section('usedCars').type('entry').search().manufacturer(manufacturer).model(model).bodyStyle(bodyStyle) %}
This is how i'm showing the price range.
{% if minPrice|length and maxPrice|length %}
{% for entry in results if entry.price <= maxPrice and entry.price >= minPrice %}
{% if minPrice is empty and maxPrice|length %}
{% for entry in results if entry.price <= maxPrice %}
and so on etc...
The trouble with this method is it's all based on a whole stack of "IF" statements and when I start to think about adding the year ranges too, my head starts to hurt. Is there an easier way to achieve the same thing?
I'd appreciate any nod in a general direction, or help simplifying my code down...