<p>If the category field is inside a matrix field, the relation to the entry is sort of indirect (since matrix blocks are elements of their own), so you need to tell Craft to look for the related category there. See <a href="https://craftcms.com/docs/3.x/relations.html#going-through-matrix" rel="nofollow noreferrer">Relations -&gt; Going through Matrix</a>.</p>
<pre><code>{% set related = craft.entries().relatedTo({
    targetElement: category,
    field: 'yourMatrixField.yourCategoryField',
}) %}
</code></pre>
<p>Replace <code>yourMatrixField</code> with the name of the matrix field containing the category field, and <code>yourCategoryField</code> with the name of the category field containing the relation.</p>

CC BY-SA 4.0
2021-08-05T07:18:37.260Z
2021-08-05T07:18:37.260Z
MoritzLost
<p>I am trying to query all entry elements related to a category but I am only able to get some of the entries to show up when I run craft.entry().relatedTo(category)</p>
<p>I have a matrix field in the entries of my 'pages' and 'news' section, which you can add categories to a category field to. When I run the above code it only returns entries in the 'news' section that are related to the category. Any help on how I could return all entries in those two sections related to a specific category?</p>

<craft3><relations><entry><category>
Entries not being related
# Entries not being related

(Asked by: username_0 on 2021-08-05)

I am trying to query all entry elements related to a category but I am only able to get some of the entries to show up when I run craft.entry().relatedTo(category)

I have a matrix field in the entries of my 'pages' and 'news' section, which you can add categories to a category field to. When I run the above code it only returns entries in the 'news' section that are related to the category. Any help on how I could return all entries in those two sections related to a specific category?

**Tags:** craft3, relations, entry, category

---

## 1 answers

### Answer by username_1 on 2021-08-05. Score: 2 | Accepted answer

If the category field is inside a matrix field, the relation to the entry is sort of indirect (since matrix blocks are elements of their own), so you need to tell Craft to look for the related category there. See Relations -> Going through Matrix.
{% set related = craft.entries().relatedTo({
    targetElement: category,
    field: 'yourMatrixField.yourCategoryField',
}) %}

Replace yourMatrixField with the name of the matrix field containing the category field, and yourCategoryField with the name of the category field containing the relation.


---

