<p>Something like this should do it:</p>

<pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::MatrixBlock);
$criteria-&gt;status = null;
$find = $criteria-&gt;find();
</code></pre>

<p>Setting <code>status</code> to null will return all elements regardless of their status.</p>

CC BY-SA 3.0
2015-08-03T16:42:38.830Z
The difficultly I'm having with the manual approach is finding the right criteria to restrict the results to the matrix block content for a specific entry id. I can query the db directly - but following the chain of relationships is proving difficult.
Tom
CC BY-SA 3.0
2015-08-03T16:36:23.013Z
2015-08-03T16:36:23.013Z
Brad Bell
<p>If you already have an entry object, and know the handle for the Matrix field, you can use:</p>

<pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::MatrixBlock);
$criteria-&gt;fieldId = craft()-&gt;fields-&gt;getFieldByHandle('matrixFieldHandle')-&gt;id;
$criteria-&gt;ownerId = $entry-&gt;id;
$criteria-&gt;status = null;
$blocks = $criteria-&gt;find();
</code></pre>

CC BY-SA 3.0
2015-08-03T17:13:04.757Z
2015-08-03T17:13:04.757Z
Tom
<p>I've got a plugin which needs to be able to access all the blocks in a matrix - regardless of if the blocks are enabled or disabled.</p>

<p>The entry objects returned by the likes of <code>craft()-&gt;entries-&gt;getEntryById</code> only seem to include blocks in the matrix fields which are enabled.</p>

<p>Is there a way to access this information through a service - or do I need to work out how this is handled in the control panel (which does show disabled matrix blocks)?</p>

<plugin-development>
Accessing disabled matrix blocks in a plugin
# Accessing disabled matrix blocks in a plugin

(Asked by: username_0 on 2015-08-03)

I've got a plugin which needs to be able to access all the blocks in a matrix - regardless of if the blocks are enabled or disabled.

The entry objects returned by the likes of `craft()->entries->getEntryById` only seem to include blocks in the matrix fields which are enabled.

Is there a way to access this information through a service - or do I need to work out how this is handled in the control panel (which does show disabled matrix blocks)?

**Tags:** plugin-development


---

## 2 answers

### Answer by username_1 on 2015-08-03. Score: 2

Something like this should do it:
$criteria = craft()->elements->getCriteria(ElementType::MatrixBlock);
$criteria->status = null;
$find = $criteria->find();

Setting status to null will return all elements regardless of their status.

> **Comments:**
> **username_0**: The difficultly I'm having with the manual approach is finding the right criteria to restrict the results to the matrix block content for a specific entry id. I can query the db directly - but following the chain of relationships is proving difficult.  

---

### Answer by username_0 on 2015-08-03. Score: 1

If you already have an entry object, and know the handle for the Matrix field, you can use:
$criteria = craft()->elements->getCriteria(ElementType::MatrixBlock);
$criteria->fieldId = craft()->fields->getFieldByHandle('matrixFieldHandle')->id;
$criteria->ownerId = $entry->id;
$criteria->status = null;
$blocks = $criteria->find();


---

