1

My client has requested to be able to filter the results page by price via a dropdown, which you can see in the attached screenshot.

Basically the results page shows a list of around 15 property developments, and is ordered alphabetically currently. I've setup two other dropdown filters to sort the categories by Location and by individual Development. And these work well. However, I'm stuck on how to actually implement this for price, and I can't find anything on the boards or documentation that have helped. So am hoping someone can give me some guidance.

The client wants the price dropdown to have the following options:

£0 - £999,999
£1,000,000 - £1,999,999
£2,000,000 - £2,999,999
£3,000,000 - £3,999,999
£4,000,000 - £4,999,999
£5,000,000+`

My initial approach is to create a tag group called priceRange and a tag field also called priceRange and I've entered the options above as tags and got them to show in the dropdown with the following code:

<form class="form-inline" action="{{ url('developments') }}" method="get">
  <div class="form-group">
    <label for="price1">Price</label>
    <div class="selectwrap">
      <select id="price1" class="form-control" name="price1" onchange="this.form.submit()">
        <option value="">All</option>
        {% for category in craft.tags.group('priceRange').order('title asc') %}
        <option value="">{{ category.title }}</option>
        {% endfor %}
      </select>
    </div>
  </div>
</form>

{% set query = "" %}
{% if craft.request.getParam('price1') and
craft.request.getParam('price1') is not empty %}
{% set query = craft.request.getParam('price1') %}
{% endif %}

{% set queryFilter = craft.categories.group('developments').search(query).order('title asc') %}

{% if queryFilter|length %}
{% for category in queryFilter %}
<div class="development-block">
..the content..
{% endfor %}

So I have them showing in the dropdown, but any help on how to actually get it filter the results by by the selected price range would be very appreciated, and then sort those results by highest price.

Or a better approach even, as I am wary with the tags approach that the client might add extra tags with different prices for the same ranges. So I would ideally like to give them a defined list of options in CMS to select from that they can't then edit if possible?

price filter

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.