I have an advanced search that searches real estate properties by the usual criteria: price range, Bedrooms, Bathrooms... In the form, the default is "Any" if they don't care about a particular option.
On the results page, I'm checking for a null value in case an option wasn't selected. Despite this, I'm still getting the message 'Key "1" for array with keys "0" does not exist' if the price option is missing. What is causing this?
My search results page looks like this:
{% set price = craft.request.getParam('p') %}
{% set price = price ? price|split('-') %}
{% set br = craft.request.getParam('br') %}
{% set br = br ? br %}
{% set ba = craft.request.getParam('ba') %}
{% set ba = ba ? ba %}
<h1>Search Results</h1>
{% set searchResults = craft.entries({
section: 'properties',
propertyPrice: price ? ['and', '>= ' ~ price[0],'<= ' ~ price[1]],
bedrooms: br ? [ 'and', '>= ' ~ br ],
bathrooms: ba ? [ 'and', '>= ' ~ ba ],
order: 'score'
}) %}
{% if searchResults|length %}
<ul>
{% for entry in searchResults %}
<li>{{ entry.title }}: {{ entry.propertyPrice|currency('USD', true) }}: BR: {{ entry.bedrooms }}, BA: {{ entry.bathrooms }}</li>
{% endfor %}
</ul>
{% else %}
<h1>No Results Found</h1>
{% endif %}