Answers.Body: <p>You'll need to do a <code>matrixBlocks</code> query first to get the IDs of all the relevant matrix blocks, then your <code>entries</code> query referencing those ids:</p>
  <pre class="lang-twig prettyprint-override"><code>{% set blockIds = craft.matrixBlocks.field('events').type('event').dropdown('categoryOne').ids() %}
  {% set eventsQuery = craft.entries.section('events').events(blockIds) %}
  </code></pre>
  <p>(Or here's the same thing if you really prefer the object syntax)...</p>
  <pre class="lang-twig prettyprint-override"><code>{% set blockIds = craft.matrixBlocks({
      field: 'events',
      type: 'event',
      dropdown: 'categoryOne'
  }).ids() %}
      
  {% set eventsQuery = craft.entries({
      section: 'events',
      events: blockIds
  }) %}
  </code></pre>
  <p><a href="https://craftcms.com/docs/4.x/matrix-blocks.html#querying-matrix-blocks" rel="nofollow noreferrer">https://craftcms.com/docs/4.x/matrix-blocks.html#querying-matrix-blocks</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-03-03T12:54:09.957Z
Answers.Text: Thanks for the answer! I'm not sure if it'll work with the way I'm filtering stuff in Sprig, but I'll see how I go.
Answers.UserDisplayName: bigdev
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-03-03T13:01:18.517Z
Answers.Text: So I think this is my issue `{% set blockIds = craft.matrixBlocks.type('event').dropdown('categoryOne').ids()` is returning the same number of items no matter the category set. It doesn't seem to filter them that way.
Answers.UserDisplayName: bigdev
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-03-03T13:30:14.947Z
Answers.Text: Looks like you just need to specify the Matrix field too: `{% set blockIds = craft.matrixBlocks.field('events').type('event').dropdown('categoryOne').ids() %}` Bingo! Thanks!
Answers.UserDisplayName: bigdev
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-03-02T10:19:26.990Z
Answers.LastActivityDate: 2023-03-03T13:36:10.470Z
Answers.LastEditDate: 2023-03-03T13:36:10.470Z
Answers.UserDisplayName: James Smith
Body: <p>I have Entries with a Matrix field called <code>events</code>. I have an Entries field and a Dropdown field inside those Matrix blocks (block type <code>event</code>). I'm currently filtering by entry using <code>andRelatedTo(['and', {targetElement: entry.id, field: 'events.entry'}])</code>.</p>
  <p>I would also like to add the ability to filter via the dropdown, but I'm unsure of how I can target that dropdown:</p>
  <pre><code>{% set eventsQuery = craft.entries({
    section: 'events',
    events.event.dropdown: 'categoryOne'
  }) %}
  
  ## I'm doing this with Sprig, so adding the relations this way
  {% do eventsQuery.andRelatedTo(['and', {targetElement: entry.id, field: events.entry}]) %}
  </code></pre>
  <p><code>events.event.dropdown: 'categoryOne'</code> is how it would work in my mind, but obviously is incorrect.</p>
  <p>Can anyone show me how I could add the dropdown inside a Matrix block as a filter? Thanks!</p>
  
Tags: <matrix><relations><plugin-sprig>
Title: Filtering entries via a dropdown inside a Matrix Block
ThreadText: # Filtering entries via a dropdown inside a Matrix Block
  
  (Asked by: username_0 on 2023-03-02)
  
  I have Entries with a Matrix field called `events`. I have an Entries field and a Dropdown field inside those Matrix blocks (block type `event`). I'm currently filtering by entry using `andRelatedTo(['and', {targetElement: entry.id, field: 'events.entry'}])`.
  
  I would also like to add the ability to filter via the dropdown, but I'm unsure of how I can target that dropdown:
  
  ```
  {% set eventsQuery = craft.entries({
    section: 'events',
    events.event.dropdown: 'categoryOne'
  }) %}
  
  ## I'm doing this with Sprig, so adding the relations this way
  {% do eventsQuery.andRelatedTo(['and', {targetElement: entry.id, field: events.entry}]) %}
  
  ```
  
  `events.event.dropdown: 'categoryOne'` is how it would work in my mind, but obviously is incorrect.
  
  Can anyone show me how I could add the dropdown inside a Matrix block as a filter? Thanks!
  
  **Tags:** matrix, relations, plugin-sprig
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-03-02. Score: 3 | Accepted answer
  
  You'll need to do a `matrixBlocks` query first to get the IDs of all the relevant matrix blocks, then your `entries` query referencing those ids:
  
  ```twig
  {% set blockIds = craft.matrixBlocks.field('events').type('event').dropdown('categoryOne').ids() %}
  {% set eventsQuery = craft.entries.section('events').events(blockIds) %}
  
  ```
  
  (Or here's the same thing if you really prefer the object syntax)...
  
  ```twig
  {% set blockIds = craft.matrixBlocks({
      field: 'events',
      type: 'event',
      dropdown: 'categoryOne'
  }).ids() %}
      
  {% set eventsQuery = craft.entries({
      section: 'events',
      events: blockIds
  }) %}
  
  ```
  
  <https://craftcms.com/docs/4.x/matrix-blocks.html#querying-matrix-blocks>
  
  > **Comments:**
  > **username_0**: Thanks for the answer! I'm not sure if it'll work with the way I'm filtering stuff in Sprig, but I'll see how I go.  
  > **username_0**: So I think this is my issue `{% set blockIds = craft.matrixBlocks.type('event').dropdown('categoryOne').ids()` is returning the same number of items no matter the category set. It doesn't seem to filter them that way.  
  > **username_0**: Looks like you just need to specify the Matrix field too: `{% set blockIds = craft.matrixBlocks.field('events').type('event').dropdown('categoryOne').ids() %}` Bingo! Thanks!  
  
  ---
  
  