<p>Rename the field handle to something else, <code>depth</code> is a deprecated attribute for ElementCriteriaModel.</p>

CC BY-SA 3.0
2017-04-21T22:23:35.273Z
2017-04-21T22:23:35.273Z
carlcs
<p>I have a search form where a user can enter width, height and depth and the search results will return any item that will "fit" into those dimensions. It works, but for some reason only if the depth is not set.</p>

<p>Form:</p>

<pre><code>&lt;input type="search" name="q" value="{{ craft.request.getParam('q') }}"&gt;
&lt;label&gt;Width&lt;/label&gt;
  &lt;input type="number" name="w" value="{{ searchWidth }}"&gt;
&lt;label&gt;Height&lt;/label&gt;
  &lt;input type="number" name="h" value="{{ searchHeight }}"&gt;
&lt;label&gt;Depth&lt;/label&gt;
  &lt;input type="number" name="d" value="{{ searchDepth }}"&gt;
</code></pre>

<p>The resulting query looks like this <code>search3?q=&amp;w=43&amp;h=44&amp;d=1000</code></p>

<p>For Results</p>

<pre><code>{% set queryParams = {
  section: 'products',
  order: 'postDate desc',
  limit: 15
  } %}

{% set searchWidth = craft.request.getParam('w') %}
{% set searchHeight = craft.request.getParam('h') %}
{% set searchDepth = craft.request.getParam('d') %}

{% if searchWidth &gt; 0 %}
  {% set finalWidth = searchWidth + 1 %}
  {% set queryParams = queryParams | merge({
    width: '&lt;= ' ~ finalWidth
    }) %}
{% endif %}

{% if searchHeight &gt; 0 %}
  {% set finalHeight = searchHeight + 1 %}
  {% set queryParams = queryParams | merge({
    height: '&lt;= ' ~ finalHeight
    }) %}
{% endif %}

{% if searchDepth &gt; 0 %}
  {% set finalDepth = searchDepth + 1 %}
  {% set queryParams = queryParams | merge({
    depth: '&lt;= ' ~ finalDepth
    }) %}
{% endif %}
</code></pre>

<p>Which I merge with my original search:</p>

<pre><code>{% set searchQ = craft.request.getParam('q') %}
{% if searchQ is not empty %}
{% set queryParams = queryParams | merge({
  search: {
  query: searchQ,
  subLeft: true,
  subRight: true
   }
 }) %}
{% endif %}
</code></pre>

<p>Everything works fine. If I enter 44 for <code>h</code> and 43 for <code>w</code> it does what it should, if finds all items smaller than the width and height. If I add something in the <code>d</code>, even 1,000 I get 0 results. If I output <code>{{ finalDepth }}</code> somewhere in the template it outputs without issue, but it finds 0 results when something is entered in the <code>d</code> search.</p>

<p>All three fields are number fields named width, height and depth. I have checked and rechecked and I am at a loss.</p>

<search>
Trouble with merging Numbers in an Advanced Search
# Trouble with merging Numbers in an Advanced Search

(Asked by: username_0 on 2017-04-21)

I have a search form where a user can enter width, height and depth and the search results will return any item that will "fit" into those dimensions. It works, but for some reason only if the depth is not set.
Form:

Width
  
Height
  
Depth
  

The resulting query looks like this search3?q=&w=43&h=44&d=1000
For Results
{% set queryParams = {
  section: 'products',
  order: 'postDate desc',
  limit: 15
  } %}

{% set searchWidth = craft.request.getParam('w') %}
{% set searchHeight = craft.request.getParam('h') %}
{% set searchDepth = craft.request.getParam('d') %}

{% if searchWidth > 0 %}
  {% set finalWidth = searchWidth + 1 %}
  {% set queryParams = queryParams | merge({
    width: '<= ' ~ finalWidth
    }) %}
{% endif %}

{% if searchHeight > 0 %}
  {% set finalHeight = searchHeight + 1 %}
  {% set queryParams = queryParams | merge({
    height: '<= ' ~ finalHeight
    }) %}
{% endif %}

{% if searchDepth > 0 %}
  {% set finalDepth = searchDepth + 1 %}
  {% set queryParams = queryParams | merge({
    depth: '<= ' ~ finalDepth
    }) %}
{% endif %}

Which I merge with my original search:
{% set searchQ = craft.request.getParam('q') %}
{% if searchQ is not empty %}
{% set queryParams = queryParams | merge({
  search: {
  query: searchQ,
  subLeft: true,
  subRight: true
   }
 }) %}
{% endif %}

Everything works fine. If I enter 44 for h and 43 for w it does what it should, if finds all items smaller than the width and height. If I add something in the d, even 1,000 I get 0 results. If I output {{ finalDepth }} somewhere in the template it outputs without issue, but it finds 0 results when something is entered in the d search.
All three fields are number fields named width, height and depth. I have checked and rechecked and I am at a loss.

**Tags:** search

---

## 1 answers

### Answer by username_1 on 2017-04-21. Score: 2 | Accepted answer

Rename the field handle to something else, `depth` is a deprecated attribute for ElementCriteriaModel.


---

