Filtering on related entries (with an array query param) 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) %}
    &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 %}


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:

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


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!
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 %}