Answers.Body: <p>Try using <code>targetElement: cat</code> instead of sourceElement – in my experience the <em>entries</em> are considered the source of the relation in cases like these, not the categories.</p>
  
  <p>Edit: Also, the <code>field</code> parameter of the <code>relatedTo</code> method shouldn't include the Matrix field's block type, only the actual category field – i.e. <code>contentBuilder.content</code>, not <code>contentBuilder.relatedCategories.content</code>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-03T00:18:30.833Z
Answers.Text: I added the actual field in the block type to the example. But, trying what you said doesn't work unfortunately.
Answers.UserDisplayName: John
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-03T00:23:38.887Z
Answers.Text: Hm. There's no need to include/specify the block type in the `field` parameter, `contentBuilder.content` should do nicely if the latter is your actual category field. Did you try with both `targetElement` and `contentBuilder.content`?
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-03T00:34:18.213Z
Answers.Text: Hmm, yes you are right, using contentBuilder.content works along with targetElement. Superb! Thanks Mats!!
Answers.UserDisplayName: John
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-03T00:44:11.727Z
Answers.Text: Awesome! I edited the answer to include that detail, for reference.
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-02T23:48:18.637Z
Answers.LastActivityDate: 2015-03-03T00:43:08.657Z
Answers.LastEditDate: 2015-03-03T00:43:08.657Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>I've got a Section that uses a Matrix field, that has a block, that has a categories field in it.</p>
  
  <p>I want to find all entries using this Matrix field, who has a categories field and has a certain category selected.</p>
  
  <p>I'm looking at the Relations documentation and trying the following code, but perhaps i'm barking up the wrong tree here?</p>
  
  <pre><code>{% set cat = craft.categories.slug('print') %}
  {% set entries = craft.entries.section('projectsEntries').relatedTo({
  sourceElement: cat,
  field: 'contentBuilder.relatedCategories.content'
  }) %}
  
  {% for entry in entries %}
  
  {{ entry.title }}
  
  {% endfor %}
  </code></pre>
  
Tags: <matrix><categories><relations>
Title: Find entries that have a category selected from a category field within a matrix block
ThreadText: # Find entries that have a category selected from a category field within a matrix block
  
  (Asked by: username_0 on 2015-03-02)
  
  I've got a Section that uses a Matrix field, that has a block, that has a categories field in it.
  
  I want to find all entries using this Matrix field, who has a categories field and has a certain category selected.
  
  I'm looking at the Relations documentation and trying the following code, but perhaps i'm barking up the wrong tree here?
  
  ```
  {% set cat = craft.categories.slug('print') %}
  {% set entries = craft.entries.section('projectsEntries').relatedTo({
  sourceElement: cat,
  field: 'contentBuilder.relatedCategories.content'
  }) %}
  
  {% for entry in entries %}
  
  {{ entry.title }}
  
  {% endfor %}
  
  ```
  
  **Tags:** matrix, categories, relations
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-03-02. Score: 3 | Accepted answer
  
  Try using `targetElement: cat` instead of sourceElement – in my experience the *entries* are considered the source of the relation in cases like these, not the categories.
  
  Edit: Also, the `field` parameter of the `relatedTo` method shouldn't include the Matrix field's block type, only the actual category field – i.e. `contentBuilder.content`, not `contentBuilder.relatedCategories.content`.
  
  > **Comments:**
  > **username_0**: I added the actual field in the block type to the example. But, trying what you said doesn't work unfortunately.  
  > **username_1**: Hm. There's no need to include/specify the block type in the `field` parameter, `contentBuilder.content` should do nicely if the latter is your actual category field. Did you try with both `targetElement` and `contentBuilder.content`?  
  > **username_0**: Hmm, yes you are right, using contentBuilder.content works along with targetElement. Superb! Thanks username_1!!  
  > **username_1**: Awesome! I edited the answer to include that detail, for reference.  
  
  ---
  
  