<p>So I finally solved this, and wanted to post the answer here for anyone that stumbles on this similar issue. All of the content for each of my blog entries is input through a single matrix field. I also included a block in that field to hold all of the entry categories, and most of my entries have multiple categories. I could not get those entries to output to the front end, no matter what I tried, until I took the categories out and made them a separate field.</p>

<p>So I now have a matrix field for my blog entry main body content, images, and videos...and a separate field for categories. Once I did that, I was able output all blog entries related to any category, and switch among the different categories to get a new summary of entries based on the category picked. There may be some way to get the previous method to work, but I sure could not solve it. In any case - all is working as planned.</p>

CC BY-SA 4.0
2018-06-27T04:55:45.490Z
https://craftcms.stackexchange.com/questions/25517/categories-related-to-matrix-fields for future questions I would suggest you to properly explain your setup
Robin Schambach
CC BY-SA 4.0
2018-06-27T01:04:25.113Z
2018-06-27T01:04:25.113Z
matt.bryant
<p>First you'll need to know what you are currently doing</p>

<pre><code>craft.categories.slug()
</code></pre>

<p>Will return a CategoryQuery with no property attached to it. So when you execute this query you'll fetch all categories. Your so called <code>category</code> variable is no category but a query that needs to be executed in order to do something</p>

<pre><code>craft.entries.relatedTo(category)
</code></pre>

<p>Same thing again: it will return an EntryQuery with all entries that related to any category in any field. So as long as an entry has a relation to what every category it will match. Then again <code>entries</code> is not an array of entries but a query that needs to be executed via <code>all()</code></p>

<p>When you loop through this query it is executed as well but with a deprecated warning because this way is not supported anymore.</p>

<p>If you are in a category page you'll likely have the <code>catetory</code> variable already injected as superglobal in your template. So there is already a category you have access to.</p>

<p>You can then do</p>

<pre><code>{% for entry in craft.entries.relatedTo(category).all() %}
</code></pre>

<p>Please make sure there are entries that are related to your current category </p>

CC BY-SA 4.0
2018-06-25T22:09:17.507Z
2018-06-25T22:09:17.507Z
Robin Schambach
<p>Trying to get all entries related to a particular blog category to output to the page. Right now I just get the correct URL for any category and a blank page. </p>

<p>Also my categories are entered into a matrix field as one of the matrix blocks. I use a single matrix field to capture all of the content for each blog entry.</p>

<p>Here is my <code>categories/_category.html</code> template code.</p>

<pre><code>{# Fetch all of the entries related to this category #}
{% set category = craft.categories.slug('') %}
{% set entries = craft.entries.relatedTo(category) %}

{# Output them #}
{% for entry in entries %}
    &lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;
{% endfor %}
</code></pre>

<p>I've tried plugging in particular category slugs into the <code>craft.categories.slug('')</code> but no help. I'm following advice from <a href="https://craftcms.com/support/entries-related-to-category" rel="nofollow noreferrer">https://craftcms.com/support/entries-related-to-category</a></p>

<p>....and</p>

<p><a href="https://craftcms.stackexchange.com/questions/15842/category-entries">Category Entries</a></p>

<p>Any ideas on what is missing?</p>

<craft3>
Can't Output Entries from Particular Blog Categories
# Can't Output Entries from Particular Blog Categories

(Asked by: username_0 on 2018-06-25)

Trying to get all entries related to a particular blog category to output to the page. Right now I just get the correct URL for any category and a blank page. 
Also my categories are entered into a matrix field as one of the matrix blocks. I use a single matrix field to capture all of the content for each blog entry.
Here is my categories/_category.html template code.
{# Fetch all of the entries related to this category #}
{% set category = craft.categories.slug('') %}
{% set entries = craft.entries.relatedTo(category) %}

{# Output them #}
{% for entry in entries %}
    {{ entry.title }}
{% endfor %}

I've tried plugging in particular category slugs into the craft.categories.slug('') but no help. I'm following advice from https://craftcms.com/support/entries-related-to-category
....and
Category Entries
Any ideas on what is missing?

**Tags:** craft3

---

## 2 answers

### Answer by username_0 on 2018-06-27. Score: 1

So I finally solved this, and wanted to post the answer here for anyone that stumbles on this similar issue. All of the content for each of my blog entries is input through a single matrix field. I also included a block in that field to hold all of the entry categories, and most of my entries have multiple categories. I could not get those entries to output to the front end, no matter what I tried, until I took the categories out and made them a separate field.

So I now have a matrix field for my blog entry main body content, images, and videos...and a separate field for categories. Once I did that, I was able output all blog entries related to any category, and switch among the different categories to get a new summary of entries based on the category picked. There may be some way to get the previous method to work, but I sure could not solve it. In any case - all is working as planned.

> **Comments:**
> **username_1**: https://craftcms.stackexchange.com/questions/25517/categories-related-to-matrix-fields for future questions I would suggest you to properly explain your setup  

---

### Answer by username_1 on 2018-06-25. Score: 1

First you'll need to know what you are currently doing
craft.categories.slug()

Will return a CategoryQuery with no property attached to it. So when you execute this query you'll fetch all categories. Your so called category variable is no category but a query that needs to be executed in order to do something
craft.entries.relatedTo(category)

Same thing again: it will return an EntryQuery with all entries that related to any category in any field. So as long as an entry has a relation to what every category it will match. Then again entries is not an array of entries but a query that needs to be executed via all()
When you loop through this query it is executed as well but with a deprecated warning because this way is not supported anymore.
If you are in a category page you'll likely have the catetory variable already injected as superglobal in your template. So there is already a category you have access to.
You can then do
{% for entry in craft.entries.relatedTo(category).all() %}

Please make sure there are entries that are related to your current category


---

