Answers.Body: <p>This should take care of it:</p>
  
  <pre><code>{% set stage = craft.request.getParam('stage') %}
  
  {# check if stage is an array #}
  {% if stage is iterable %}
  
      {% for stageItem in stage %}
  
          {# make sure stageItem has content #}
          {% if stageItem is not empty %}
  
              {{ stageItem }}
              {# would output the selected stage.value #}
  
          {% endif %}
  
      {% endfor %}
  
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-16T13:38:03.543Z
Answers.Text: I edited this to make it a little stronger. We want to test the array to make sure it's an array, but it's each item that we want to make sure is not empty.
Answers.UserDisplayName: Dan Ott
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-15T18:17:12.910Z
Answers.LastActivityDate: 2016-06-16T13:36:29.093Z
Answers.LastEditDate: 2016-06-16T13:36:29.093Z
Answers.UserDisplayName: Dan Ott
Body: <p>I'm getting myself into a potential pickle here and wanting to know the best way to get apply filters on the current scenario:</p>
  
  <p>I have a central <code>business</code> section which is getting populated via an API (<em>just a little background info</em>) and I have a second section <code>drugs</code> which has a Entries field that contains a link to <code>business</code>.</p>
  
  <p>I've designed a table that pulls in all this info that looks a little something like this:</p>
  
  <p><a href="https://i.sstatic.net/PgAuH.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/PgAuH.png" alt="company drug table"></a>
  I've built out the table like this:</p>
  
  <pre><code>{# DEFAULTS #}
  {% set queryParams = {
      section: 'business',
      order: 'title asc',
      limit: 30
  } %}
  {% for entry in craft.entries(queryParams) %}
      &lt;div class="row"&gt;
          &lt;div class="td td--comapny"&gt;&lt;small&gt;{{entry.title}}&lt;/small&gt; &lt;b&gt;{{entry.business_name}}&lt;/b&gt;&lt;/div&gt;
          &lt;div class="td td--price"&gt;
          {{entry.business_price}}
          {% if "+" in entry.business_change %}
              &lt;small style="color:#0c0"&gt;{{entry.business_change}} {{entry.business_percentChange}}&lt;/small&gt;
          {% else %}
              &lt;small style="color:#c00"&gt;{{entry.business_change}} {{entry.business_percentChange}}&lt;/small&gt;
          {% endif %}
          &lt;/div&gt;
          &lt;div class="td td--market_cap"&gt;${{entry.business_market_cap}}&lt;/div&gt;
          &lt;div class="td td--shares"&gt;{{entry.business_number_of_shares|number}}&lt;/div&gt;
          &lt;div class="td td--short_ratio"&gt;{{entry.business_shortRatio}}&lt;/div&gt;
          &lt;div class="td td--short_ratio"&gt;{{entry.dateUpdated}}&lt;/div&gt;
          &lt;br style="clear:both" /&gt;
          &lt;table style="width: 100%;"&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th style="text-align: left;width:20%"&gt;Drug&lt;/th&gt;
                      &lt;th style="text-align: left;width:30%"&gt;Indication&lt;/th&gt;
                      &lt;th style="text-align: left;width:20%"&gt;Stage&lt;/th&gt;
                      &lt;th style="text-align: left;width:30%"&gt;News&lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
              {% set relatedDrugs = craft.entries.section('drug').relatedTo(entry) %}
              {% for drug in relatedDrugs %}
              &lt;tr&gt;
                  &lt;td&gt;{{ drug.title }}&lt;/td&gt;
                  &lt;td&gt;{{ drug.drug_indication}}&lt;/td&gt;
                  &lt;td&gt;{{ drug.drug_stage.label}}&lt;/td&gt;
                  &lt;td&gt;&lt;a href="{{ drug.drug_press_link}}"&gt;{{ drug.drug_note}}&lt;/a&gt;&lt;/td&gt;
              &lt;/tr&gt;
              {% endfor %}
              &lt;/tbody&gt;
          &lt;/table&gt;
      &lt;/div&gt;
  {% endfor %}
  </code></pre>
  
  <p>Now – the pickle is the filtering side of things: I'm wanting to filter on the drug stage, AND to make matters even more exciting this is a multi-select filter which I've done like this:</p>
  
  <pre><code>&lt;fieldset&gt;
      &lt;legend&gt;Stage&lt;/legend&gt;
      {% set stage = craft.fields.getFieldByHandle('drug_stage') %}
      {% for stage in stage.settings.options %}
          {% if loop.first %}&lt;select name="stage[]" multiple&gt;{% endif %}
            &lt;option value="{{stage.value}}"&gt;{{stage.label}}&lt;/option&gt;
          {% if loop.last %}&lt;/select&gt;{% endif %}
      {% endfor %}
  &lt;/fieldset&gt;
  </code></pre>
  
  <p>I'm not really sure how to enable multiple params of the same name so I've called it <code>stage[]</code> which handily returns an array. The problem I'm having now is building that new param filter query... I got as far as this and stared blankly at the screen for 10 minutes (I'm no programmer...)</p>
  
  <pre><code>{% set stage = craft.request.getParam('stage') %}
  {% if stage is not empty %}
      {# NO IDEA #}
  {% endif %}
  </code></pre>
  
  <p>I really have no idea where to start. Any pointers or help would be fantastic!</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-09T21:56:13.977Z
Comments.Text: Hey @DarrenWood, could you accept Dan's answer if it was helpful or post your own answer if you solved it differently?
Comments.UserDisplayName: Matt Stein
Tags: <templating><relations><params><filtering>
Title: Filtering on related entries (with an array query param)
ThreadText: # Filtering on related entries (with an array query param)
  
  (Asked by: username_0 on 2016-05-31)
  
  I'm getting myself into a potential pickle here and wanting to know the best way to get apply filters on the current scenario:
  
  I have a central `business` section which is getting populated via an API (*just a little background info*) and I have a second section `drugs` which has a Entries field that contains a link to `business`.
  
  I've designed a table that pulls in all this info that looks a little something like this:
  
  [![company drug table](https://i.sstatic.net/PgAuH.png)](https://i.sstatic.net/PgAuH.png)
  I've built out the table like this:
  
  ```
  {# DEFAULTS #}
  {% set queryParams = {
      section: 'business',
      order: 'title asc',
      limit: 30
  } %}
  {% for entry in craft.entries(queryParams) %}
      <div class="row">
          <div class="td td--comapny"><small>{{entry.title}}</small> <b>{{entry.business_name}}</b></div>
          <div class="td td--price">
          {{entry.business_price}}
          {% if "+" in entry.business_change %}
              <small style="color:#0c0">{{entry.business_change}} {{entry.business_percentChange}}</small>
          {% else %}
              <small style="color:#c00">{{entry.business_change}} {{entry.business_percentChange}}</small>
          {% endif %}
          </div>
          <div class="td td--market_cap">${{entry.business_market_cap}}</div>
          <div class="td td--shares">{{entry.business_number_of_shares|number}}</div>
          <div class="td td--short_ratio">{{entry.business_shortRatio}}</div>
          <div class="td td--short_ratio">{{entry.dateUpdated}}</div>
          <br style="clear:both" />
          <table style="width: 100%;">
              <thead>
                  <tr>
                      <th style="text-align: left;width:20%">Drug</th>
                      <th style="text-align: left;width:30%">Indication</th>
                      <th style="text-align: left;width:20%">Stage</th>
                      <th style="text-align: left;width:30%">News</th>
                  </tr>
              </thead>
              <tbody>
              {% set relatedDrugs = craft.entries.section('drug').relatedTo(entry) %}
              {% for drug in relatedDrugs %}
              <tr>
                  <td>{{ drug.title }}</td>
                  <td>{{ drug.drug_indication}}</td>
                  <td>{{ drug.drug_stage.label}}</td>
                  <td><a href="{{ drug.drug_press_link}}">{{ drug.drug_note}}</a></td>
              </tr>
              {% endfor %}
              </tbody>
          </table>
      </div>
  {% endfor %}
  
  ```
  
  Now – the pickle is the filtering side of things: I'm wanting to filter on the drug stage, AND to make matters even more exciting this is a multi-select filter which I've done like this:
  
  ```
  <fieldset>
      <legend>Stage</legend>
      {% set stage = craft.fields.getFieldByHandle('drug_stage') %}
      {% for stage in stage.settings.options %}
          {% if loop.first %}<select name="stage[]" multiple>{% endif %}
            <option value="{{stage.value}}">{{stage.label}}</option>
          {% if loop.last %}</select>{% endif %}
      {% endfor %}
  </fieldset>
  
  ```
  
  I'm not really sure how to enable multiple params of the same name so I've called it `stage[]` which handily returns an array. The problem I'm having now is building that new param filter query... I got as far as this and stared blankly at the screen for 10 minutes (I'm no programmer...)
  
  ```
  {% set stage = craft.request.getParam('stage') %}
  {% if stage is not empty %}
      {# NO IDEA #}
  {% endif %}
  
  ```
  
  I really have no idea where to start. Any pointers or help would be fantastic!
  
  **Tags:** templating, relations, params, filtering
  
  > **Comments:**
  > **username_1**: Hey @username_0, could you accept Dan's answer if it was helpful or post your own answer if you solved it differently?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2016-06-15. Score: 1 | Accepted answer
  
  This should take care of it:
  
  ```
  {% set stage = craft.request.getParam('stage') %}
  
  {# check if stage is an array #}
  {% if stage is iterable %}
  
      {% for stageItem in stage %}
  
          {# make sure stageItem has content #}
          {% if stageItem is not empty %}
  
              {{ stageItem }}
              {# would output the selected stage.value #}
  
          {% endif %}
  
      {% endfor %}
  
  {% endif %}
  
  ```
  
  > **Comments:**
  > **username_2**: I edited this to make it a little stronger. We want to test the array to make sure it's an array, but it's each item that we want to make sure is not empty.  
  
  ---
  
  