<p>The right Field ID to add is the <code>Matrix</code> field id as defined in the <code>Fields</code> section.  Do not use the ids of the matrix block fields.</p>

CC BY-SA 4.0
2018-06-21T05:27:01.173Z
2018-06-21T05:27:01.173Z
biko
<pre><code>$blocks = MatrixBlock::find()-&gt;relatedTo($entry)-&gt;all();
</code></pre>

<p>The above returns the correct blocks but all fields are returned as NULL.</p>

<p>I've read over at <a href="https://github.com/craftcms/cms/issues/1789" rel="nofollow noreferrer">GitHub</a> that we need to specify a fieldId param but can't seem to figure out how.  The below e.g. doesn't work:</p>

<pre><code>$blocks = MatrixBlock::find()-&gt;relatedTo($entry)-&gt;fieldId([33])-&gt;all();
</code></pre>

<p>Help anyone?</p>

CC BY-SA 4.0
2018-06-21T05:00:17.043Z
Is your field id correct? You need to insert an id and not an array
Robin Schambach
CC BY-SA 4.0
2018-06-21T05:25:59.983Z
@RobinSchambach Ah yes my field id was wrong...  I was adding the field id of the matrix block.  The right ID to add is the Matrix field id as defined in the Fields section.  Thank you!
biko
<matrix><craft3><plugin-elementapi><query>
Matrix block fields returning NULL when using MatrixBlock query
# Matrix block fields returning NULL when using MatrixBlock query

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

$blocks = MatrixBlock::find()->relatedTo($entry)->all();

The above returns the correct blocks but all fields are returned as NULL.
I've read over at GitHub that we need to specify a fieldId param but can't seem to figure out how.  The below e.g. doesn't work:
$blocks = MatrixBlock::find()->relatedTo($entry)->fieldId([33])->all();

Help anyone?

**Tags:** matrix, craft3, plugin-elementapi, query

> **Comments:**
> **username_1**: Is your field id correct? You need to insert an id and not an array  
> **username_0**: @RobinSchambach Ah yes my field id was wrong...  I was adding the field id of the matrix block.  The right ID to add is the Matrix field id as defined in the Fields section.  Thank you!  

---

## 1 answers

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

The right Field ID to add is the `Matrix` field id as defined in the `Fields` section. Do not use the ids of the matrix block fields.


---

