Answers.Body: <p>You have to insert your matrix field into the rated to param like <a href="https://docs.craftcms.com/v2/relations.html#going-through-matrix" rel="nofollow noreferrer">here</a> </p>
  
  <pre><code>{% set entries = craft.entries.section('subShops').relatedTo({
      targetElement: sandwich, 
      field: 'sandwichBuilder.breads' 
  }) %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-07T08:54:20.233Z
Answers.Text: My setup is a bit different.  My Matrix field is a categories field.  So in my entry matrix field I am selecting multiple categories.  I need to list out the entry and all the category selections that go with that matrix field.  I hope I am making sense as I am trying to understand this all myself.
Answers.UserDisplayName: Vin
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-07T12:31:21.763Z
Answers.Text: It does not matter what you select. These are all elements, there is no difference between entries and cetegories since they extend the same baseRelationField that selects elements. Craft can only restrict the elements type you are able to choose from but you could insert entries as well as categories or users or whatever you want
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-07T19:15:44.093Z
Answers.Text: Ok I get it, with Craft it's semantics, one thing over another does not matter for performance like having categories or entries.  I am trying to pull records and assign them to their parent record.  So thinking having an entry and intersecting with 3 categories may be to complex.  For example, I wanted an entry to be the Sub Shop and separate categories to be bread, meat an condiments.  I wanted to do a search from the frontend and match bread and meat combo and show the underlying condiments for each sandwich in the record.
Answers.UserDisplayName: Vin
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-07T20:48:29.733Z
Answers.Text: Yes you can do so with the related to parameter. I don't see any issue. That's the strength of Craft . You can create complex relationships between elements without problems. Relating 3+ categories with an entry and search for them is no big deal
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-07T21:07:15.730Z
Answers.Text: That is the trick I am trying to accomplish but have failed at doing.  Read through all the docs and not seeing the code solution.
Answers.UserDisplayName: Vin
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-07T21:52:46.807Z
Answers.Text: I changed the placeholders according to your structure and field handles
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-08T03:52:16.923Z
Answers.Text: In your example code "sandwich" is a Entries source, I only have one entry sournce called subShop not two. The rest is in a matrix field called sandwichBuilder.  Let me shoot my example here soon.
Answers.UserDisplayName: Vin
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-08T06:43:56.407Z
Answers.Text: Sandwich is not an entry source... It's an element. Like I already said it does not matter what you insert. You can pass users, as well as categories, matrix fields, tags or whatever elements you want. If you only have one entry what's the point of searching for it anyway? This was your question wasn't it "How can I build my query so that I can find all entries using a category of bread"
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-08T07:09:36.970Z
Answers.Text: Thanks Robin, appreciate all your help, I have not figured it out but I will keep hammering away.
Answers.UserDisplayName: Vin
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-08T07:17:59.447Z
Answers.Text: Maybe you should describe what you want properly and with Craft terms. It's a little bit confusing because you said different things in your comments and in your question without answering our questions
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-08T07:30:47.147Z
Answers.Text: Truthfully I sound confused because I am, it's not the way you have explained it, you have been great.  If I said explain how to play an A diminished chord, give me the structure and music was new to you, it would be a confusing time.  That is Craft to me. But I figured out I needed to set the variable `{% set degrees = craft.categories.group('sandwich') %}.  That is what I was missing.
Answers.UserDisplayName: Vin
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-07T05:07:24.287Z
Answers.LastActivityDate: 2018-04-07T21:48:00.037Z
Answers.LastEditDate: 2018-04-07T21:48:00.037Z
Answers.UserDisplayName: Robin Schambach
Body: <p>Please help me build my sandwich locator maker :)</p>
  
  <ul>
  <li>I have 3 categories, breads, meats, condiments  </li>
  <li>I have a <strong>Section</strong> called <em>subShops</em> with a matrix field.</li>
  <li>My matrix field is called <em>sandwichBuilder</em>, <strong>fields:</strong> breads, meats, condiments</li>
  <li>This matrix field is my entry I use for building the sandwiches that the <em>suShops</em> offer.</li>
  </ul>
  
  <p>I want to keep my Categories to make it easy for structure and searching.</p>
  
  <p><strong>How can I build my query so that I can find all entries using a category of bread (over 200 sub categories for bread)?</strong>  I want the ability to only show those subShops that carry a certain breads based on URL segments (<a href="http://example.com/breads/spelt" rel="nofollow noreferrer">http://example.com/breads/spelt</a>).</p>
  
  <p>Basically, this above url example would list all the subShops that carry spelt bread, so it would display each group including - <strong>subShop, bread and typical meats that go best with spelt</strong>.</p>
  
  <p>I have tried various ways and many hours trying to figure it out but with unusual results.  My code below is my baseline, but need some help from anyone willing to offer examples.  This is a pet project and I do plan on sharing the code when complete.</p>
  
  <pre><code>{% set entries = craft.entries.relatedTo(sanwiches).all() %}
  
  {% for entry in entries %}
  {{ entry.title }}
  
  {% for row in entry.matrixA %}
   {% for option in row.matrixB %}
      {{ option }}
      {% endfor %}
   {% endfor %}
  {% endfor %}
  </code></pre>
  
Tags: <matrix><categories><relatedto>
Title: Categories Related To Matrix Fields
ThreadText: # Categories Related To Matrix Fields
  
  (Asked by: username_0 on 2018-04-06)
  
  Please help me build my sandwich locator maker :)
  
  * I have 3 categories, breads, meats, condiments
  * I have a **Section** called *subShops* with a matrix field.
  * My matrix field is called *sandwichBuilder*, **fields:** breads, meats, condiments
  * This matrix field is my entry I use for building the sandwiches that the *suShops* offer.
  
  I want to keep my Categories to make it easy for structure and searching.
  
  **How can I build my query so that I can find all entries using a category of bread (over 200 sub categories for bread)?** I want the ability to only show those subShops that carry a certain breads based on URL segments (<http://example.com/breads/spelt>).
  
  Basically, this above url example would list all the subShops that carry spelt bread, so it would display each group including - **subShop, bread and typical meats that go best with spelt**.
  
  I have tried various ways and many hours trying to figure it out but with unusual results. My code below is my baseline, but need some help from anyone willing to offer examples. This is a pet project and I do plan on sharing the code when complete.
  
  ```
  {% set entries = craft.entries.relatedTo(sanwiches).all() %}
  
  {% for entry in entries %}
  {{ entry.title }}
  
  {% for row in entry.matrixA %}
   {% for option in row.matrixB %}
      {{ option }}
      {% endfor %}
   {% endfor %}
  {% endfor %}
  
  ```
  
  **Tags:** matrix, categories, relatedto
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-04-07. Score: 2
  
  You have to insert your matrix field into the rated to param like [here](https://docs.craftcms.com/v2/relations.html#going-through-matrix)
  
  ```
  {% set entries = craft.entries.section('subShops').relatedTo({
      targetElement: sandwich, 
      field: 'sandwichBuilder.breads' 
  }) %}
  
  ```
  
  > **Comments:**
  > **username_0**: My setup is a bit different.  My Matrix field is a categories field.  So in my entry matrix field I am selecting multiple categories.  I need to list out the entry and all the category selections that go with that matrix field.  I hope I am making sense as I am trying to understand this all myself.  
  > **username_1**: It does not matter what you select. These are all elements, there is no difference between entries and cetegories since they extend the same baseRelationField that selects elements. Craft can only restrict the elements type you are able to choose from but you could insert entries as well as categories or users or whatever you want  
  > **username_0**: Ok I get it, with Craft it's semantics, one thing over another does not matter for performance like having categories or entries.  I am trying to pull records and assign them to their parent record.  So thinking having an entry and intersecting with 3 categories may be to complex.  For example, I wanted an entry to be the Sub Shop and separate categories to be bread, meat an condiments.  I wanted to do a search from the frontend and match bread and meat combo and show the underlying condiments for each sandwich in the record.  
  > **username_1**: Yes you can do so with the related to parameter. I don't see any issue. That's the strength of Craft . You can create complex relationships between elements without problems. Relating 3+ categories with an entry and search for them is no big deal  
  > **username_0**: That is the trick I am trying to accomplish but have failed at doing.  Read through all the docs and not seeing the code solution.  
  > **username_1**: I changed the placeholders according to your structure and field handles  
  > **username_0**: In your example code "sandwich" is a Entries source, I only have one entry sournce called subShop not two. The rest is in a matrix field called sandwichBuilder.  Let me shoot my example here soon.  
  > **username_1**: Sandwich is not an entry source... It's an element. Like I already said it does not matter what you insert. You can pass users, as well as categories, matrix fields, tags or whatever elements you want. If you only have one entry what's the point of searching for it anyway? This was your question wasn't it "How can I build my query so that I can find all entries using a category of bread"  
  > **username_0**: Thanks username_1, appreciate all your help, I have not figured it out but I will keep hammering away.  
  > **username_1**: Maybe you should describe what you want properly and with Craft terms. It's a little bit confusing because you said different things in your comments and in your question without answering our questions  
  > **username_0**: Truthfully I sound confused because I am, it's not the way you have explained it, you have been great.  If I said explain how to play an A diminished chord, give me the structure and music was new to you, it would be a confusing time.  That is Craft to me. But I figured out I needed to set the variable `{% set degrees = craft.categories.group('sandwich') %}.  That is what I was missing.  
  
  ---
  
  