<p>Figured it out! I hadn't given my select field the correct name!</p>
<p>This code now works, so I setup the default value and queries as before:</p>
<pre><code>{% set projectsCategories = projectsCategories ?? [] %}

{% set catQuery = craft.entries()
  .section('projectsCategories')
 %}

{% set cats =catQuery.all() %} 

{% set entryQuery = craft.entries({
    section: 'projects',
    relatedTo: projectsCategories,
}) %}
</code></pre>
<p>then the key bit — putting the correct <strong>name</strong> value to match the  'projectsCategories' variable</p>
<pre><code>&lt;select sprig id=&quot;category&quot; name=&quot;projectsCategories&quot;&gt;
    
   &lt;option value=&quot;&quot;&gt;All&lt;/option&gt;
    
   {% for category in cats %}
    
   &lt;option value=&quot;{{category}}&quot; &gt;{{ category.title }}&lt;/option&gt;
                                
   {% endfor %}
                            
 &lt;/select&gt;
</code></pre>
<p>I can now filter by related entries...</p>
<p>Thanks again to @ben-croker for his videos, I should have watched the Sprig Filters / 2. Setting Default Values clip more closely, it explains how to name select fields...</p>
<p><a href="https://putyourlightson.com/sprig/videos" rel="nofollow noreferrer">https://putyourlightson.com/sprig/videos</a></p>

CC BY-SA 4.0
2024-10-08T09:03:00.820Z
2024-10-08T09:03:00.820Z
dezbat
<p>In this case <code>{{ category }}</code> would be outputting the title of the category, but that can't be used as a <code>relatedTo</code> param. If you update it to <code>&lt;option value=&quot;{{ category.id }}&quot;&gt;</code> it should work.</p>

CC BY-SA 4.0
2024-10-08T04:20:18.540Z
thanks for looking @revlis  — unfortunately that does not work...
dezbat
CC BY-SA 4.0
2024-10-08T03:44:52.797Z
2024-10-08T03:44:52.797Z
revlis
<p>I have a Sprig board listing architect's projects, built in Craft 5. This is working pretty well with a search, date ordering of entries etc.</p>
<p>But — I am having trouble with a dropdown that I'd like to use to <strong>filter entries by means of selecting ONE of their related entries from the 'projectsCategories' section.</strong> This entry-relations tactic is used instead of the older 'categories' method.</p>
<p>At the moment I set things up like this</p>
<pre><code>{% set projectsCategories = projectsCategories ?? [] %}

{# setup the project category query — works fine #}
{% set catQuery = craft.entries()
  .section('projectsCategories')
 %}

{% set cats =catQuery.all() %} 

{# Generate the entry query for the projects, also works well #}
{% set entryQuery = craft.entries({
    section: 'projects',
    relatedTo: projectsCategories,
}) %}
</code></pre>
<p>and this is the code for my dropdown category-filter selector on the Springboard, next to a search field (which works well!). <strong>This lists the 'projectsCategories' correctly, but NOTHING happens when I select / use the dropdown.</strong></p>
<p>I am in the dark as to how to define the filter request here using Sprig. Any help / advice MUCH appreciated!</p>
<pre><code>&lt;label for=&quot;catFilter&quot;&gt;Filter by category&lt;/label&gt;
             
      &lt;select sprig id=&quot;category&quot; name=&quot;catFilter&quot;&gt;

         &lt;option value=&quot;&quot;&gt;All&lt;/option&gt;

         {% for category in cats %}

         &lt;option value=&quot;{{category}}&quot; &gt;{{ category.title }}&lt;/option&gt;
                            
         {% endfor %}
                        
      &lt;/select&gt;
</code></pre>

<sections><craft5><plugin-sprig><filtering>
How to use Sprig to filter by related entries using a dropdown
# How to use Sprig to filter by related entries using a dropdown

(Asked by: username_0 on 2024-10-08)

I have a Sprig board listing architect's projects, built in Craft 5. This is working pretty well with a search, date ordering of entries etc.
But — I am having trouble with a dropdown that I'd like to use to filter entries by means of selecting ONE of their related entries from the 'projectsCategories' section. This entry-relations tactic is used instead of the older 'categories' method.
At the moment I set things up like this
{% set projectsCategories = projectsCategories ?? [] %}

{# setup the project category query — works fine #}
{% set catQuery = craft.entries()
  .section('projectsCategories')
 %}

{% set cats =catQuery.all() %} 

{# Generate the entry query for the projects, also works well #}
{% set entryQuery = craft.entries({
    section: 'projects',
    relatedTo: projectsCategories,
}) %}

and this is the code for my dropdown category-filter selector on the Springboard, next to a search field (which works well!). This lists the 'projectsCategories' correctly, but NOTHING happens when I select / use the dropdown.
I am in the dark as to how to define the filter request here using Sprig. Any help / advice MUCH appreciated!
Filter by category
             
      

         All

         {% for category in cats %}

         {{ category.title }}
                            
         {% endfor %}

**Tags:** sections, craft5, plugin-sprig, filtering


---

## 2 answers

### Answer by username_0 on 2024-10-08. Score: 1 | Accepted answer

Figured it out! I hadn't given my select field the correct name!
This code now works, so I setup the default value and queries as before:
{% set projectsCategories = projectsCategories ?? [] %}

{% set catQuery = craft.entries()
  .section('projectsCategories')
 %}

{% set cats =catQuery.all() %} 

{% set entryQuery = craft.entries({
    section: 'projects',
    relatedTo: projectsCategories,
}) %}

then the key bit — putting the correct name value to match the  'projectsCategories' variable

    
   All
    
   {% for category in cats %}
    
   {{ category.title }}
                                
   {% endfor %}
                            
 

I can now filter by related entries...
Thanks again to @ben-croker for his videos, I should have watched the Sprig Filters / 2. Setting Default Values clip more closely, it explains how to name select fields...
https://putyourlightson.com/sprig/videos


---

### Answer by username_1 on 2024-10-08. Score: 1

In this case `{{ category }}` would be outputting the title of the category, but that can't be used as a `relatedTo` param. If you update it to  it should work.

> **Comments:**
> **username_0**: thanks for looking @username_1  — unfortunately that does not work...  

---

