I'm building a property search form and searching by different types of fields in Craft.
Here are my questions:
How can I get a list of the unique cities in the entries section to declare my form options?
I'm stuck on searching by square feet. (see # sf # section in my code) My plan is to let the user select from a few different ranges of square footage. What I was trying to accomplish below is if my search parameter is "sf=1", the field buildingSQFT is searched for numbers in between 10000 and 20000. I would then set up different ranges based on the parameter.
I'm not sure if this is a good way to do this. Your input has to how to best accomplish this is appreciated.
{% if not craft.request.isAjax %}
{# set base params #}
{% set params = {
section: 'propertiesSection',
limit: null
} %}
{% set relatedParams = ['and'] %}
{# status #}
{% if craft.request.getParam('status') %}
{% set status = craft.categories.group('propertyStatus').slug(craft.request.getParam('status')) %}
{% set relatedParams = relatedParams|merge([{ targetElement:status }]) %}
{% endif %}
{# city #}
{% set city = craft.request.getParam('city') %}
{% if city %}
{% set params = params|merge({'city':city}) %}
{% endif %}
{# sf #}
{% set sf = craft.request.getParam('sf') %}
{% if sf == "1" %}
{% set params = params|merge({'buildingSQFT':range(10000,20000)}) %}
{% endif %}
{# add relatedParams to params #}
{% if relatedParams|length > 1 %}
{% set params = params|merge({'relatedTo':relatedParams}) %}
{% endif %}
{% set entries = craft.entries(params).search() %}
{% if entries|length %}