<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>

CC BY-SA 3.0
2016-06-16T13:38:03.543Z
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.
Dan Ott
CC BY-SA 3.0
2016-06-15T18:17:12.910Z
2016-06-16T13:36:29.093Z
2016-06-16T13:36:29.093Z
Dan Ott
<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>

CC BY-SA 3.0
2017-05-09T21:56:13.977Z
Hey @DarrenWood, could you accept Dan's answer if it was helpful or post your own answer if you solved it differently?
Matt Stein
<templating><relations><params><filtering>
Filtering on related entries (with an array query param)
# 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:

I've built out the table like this:
{# DEFAULTS #}
{% set queryParams = {
    section: 'business',
    order: 'title asc',
    limit: 30
} %}
{% for entry in craft.entries(queryParams) %}
    
        {{entry.title}} {{entry.business_name}}
        
        {{entry.business_price}}
        {% if "+" in entry.business_change %}
            {{entry.business_change}} {{entry.business_percentChange}}
        {% else %}
            {{entry.business_change}} {{entry.business_percentChange}}
        {% endif %}
        
        ${{entry.business_market_cap}}
        {{entry.business_number_of_shares|number}}
        {{entry.business_shortRatio}}
        {{entry.dateUpdated}}
        
        
            
                
                    Drug
                    Indication
                    Stage
                    News
                
            
            
            {% set relatedDrugs = craft.entries.section('drug').relatedTo(entry) %}
            {% for drug in relatedDrugs %}
            
                {{ drug.title }}
                {{ drug.drug_indication}}
                {{ drug.drug_stage.label}}
                {{ drug.drug_note}}
            
            {% endfor %}
            
        
    
{% 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:

    Stage
    {% set stage = craft.fields.getFieldByHandle('drug_stage') %}
    {% for stage in stage.settings.options %}
        {% if loop.first %}{% endif %}
          {{stage.label}}
        {% if loop.last %}{% endif %}
    {% endfor %}


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 @DarrenWood, 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.  

---

