I'm attempting to build a filter that queries entries of a section based on two criteria: A selection of one or more categories (inclusive), and a single related entry (exclusive).
Specifically, the entries are from the "technologies" section. Each technology is related to one or more categories and a single "institution" entry.
The first step is to allow a user to, for example, select two categories (like "Information Technology" and "Medical Devices") and have the results be inclusive. Easily done with a relatedTo "or" parameter.
But next, I'd like the user to be able to select a single institution, and return only the previous results that are also associated with that institution (like "UW-Oshkosh"). This filter requires an additional relatedTo "and" parameter.
My attempt to add two different relatedTo parameters to the same query (detailed below) doesn't fly -- it will only honor the last relatedTo request:
{% set params = {
section: 'technologies',
limit: null
} %}
{% if technologyIds|length %}
{% set paramTechnologyRelation = ['or'] %}
{% for technologyId in technologyIds %}
{% set paramTechnologyRelation = paramTechnologyRelation|merge([{ targetElement:technologyId }]) %}
{% endfor %}
{% set params = params|merge({relatedTo: paramTechnologyRelation}) %}
{% endif %}
{% if institutionId != "" %}
{% set paramInstitutionRelation = ['and'] %}
{% set paramInstitutionRelation = paramInstitutionRelation|merge([{ targetElement:institutionId }]) %}
{% set params = params|merge({relatedTo: paramInstitutionRelation}) %}
{% endif %}
{% set technologyResults = craft.entries(params) %}
{% paginate technologyResults.limit(10) as technologies %}
...
{% endpaginate %}
I'm trying to think of other approaches -- Is is possible to run a second query on an array of entries? Any ideas on how to best approach this? Thanks for any insights.