<p>Came across this same situation myself. Was able to resolve with:</p>

<p><code>$entry-&gt;entriesFieldWithDisabledEntry-&gt;status(null)-&gt;first()</code></p>

CC BY-SA 3.0
2018-02-26T09:46:14.663Z
This sounds perfect. Nice one.
Clive Portman
CC BY-SA 4.0
2019-03-28T15:52:04.080Z
Just what I was looking for. Thanks!
Cavell Blood
CC BY-SA 4.0
2020-10-29T14:08:44.857Z
Do you maybe have a Twig solution also? just opened https://craftcms.stackexchange.com/questions/36514/craft-3-twig-search-query-for-entry-with-custom-entriesfield-containing-disabl
Kevon
CC BY-SA 3.0
2018-02-24T22:20:26.530Z
2018-02-24T22:20:26.530Z
Chase Giunta
<p>To pull both enabled and disabled entries from an Entries field, you can do this:</p>

<pre><code>$entry-&gt;entriesField-&gt;status = 'any';
$relatedEntries = $entry-&gt;entriesField-&gt;find();
</code></pre>

CC BY-SA 3.0
2016-07-27T14:03:16.770Z
2016-07-27T14:28:04.953Z
2016-07-27T14:28:04.953Z
Mats Mikkel Rummelhoff
<p>Related fields will always ignore disabled entries.</p>

<p>Instead of disabling entries, you could add a lightswitch field to your entries to indicate whether or not they are disabled. This would preserve relations to those entries and would return all entries, regardless of the value of the lightswitch field.</p>

<p>When fetching entries in other circumstances, if you only wanted to show enabled entries, you would need to always need to explicitly include a condition that the lightswitch was on (<code>=='1'</code>).</p>

CC BY-SA 3.0
2016-07-27T10:24:33.050Z
Thanks Steve. I'd prefer to do this without querying the DB for the disabled entry, so if you're right, then this is what I'll have to do as a workaround.
Clive Portman
CC BY-SA 3.0
2016-07-27T10:27:25.897Z
It's the easiest way to handle it. I've used a similar system on a site I've built recently and it works really well. As far as I know, it's the only way to keep relations live whilst disabling direct access to entries that are the target of those relations.
Steve Rowling
CC BY-SA 3.0
2016-07-27T10:22:31.037Z
2016-07-27T10:22:31.037Z
Steve Rowling
<p>I'm looping through products (<code>$rawProduct</code>) within Craft Commerce, within a plugin, and returning products which fulfill a certain criteria. I'm then returning a <code>$products</code> array of objects with the following:</p>

<pre><code>$product = new \stdClass;
$product-&gt;url = $rawProduct-&gt;url;
$product-&gt;courseTitle = $rawProduct-&gt;relatedFieldTitle[0]['title'];
$product-&gt;courseUrl = $rawProduct-&gt;relatedFieldTitle[0]['url'];
array_push($products, $product);
</code></pre>

<p>This is working great. However, when the target entry of the related field is disabled, lines three and four above are returning empty. I'd like to get this information no matter whether the target entry is disabled. Any ideas?</p>

<plugin-development><relations>
Get disabled related entry's data within plugin
# Get disabled related entry's data within plugin

(Asked by: username_0 on 2016-07-27)

I'm looping through products ($rawProduct) within Craft Commerce, within a plugin, and returning products which fulfill a certain criteria. I'm then returning a $products array of objects with the following:
$product = new \stdClass;
$product->url = $rawProduct->url;
$product->courseTitle = $rawProduct->relatedFieldTitle[0]['title'];
$product->courseUrl = $rawProduct->relatedFieldTitle[0]['url'];
array_push($products, $product);

This is working great. However, when the target entry of the related field is disabled, lines three and four above are returning empty. I'd like to get this information no matter whether the target entry is disabled. Any ideas?

**Tags:** plugin-development, relations


---

## 3 answers

### Answer by username_1 on 2018-02-24. Score: 3 | Accepted answer

Came across this same situation myself. Was able to resolve with:

`$entry->entriesFieldWithDisabledEntry->status(null)->first()`

> **Comments:**
> **username_0**: This sounds perfect. Nice one.  
> **username_2**: Just what I was looking for. Thanks!  
> **username_3**: Do you maybe have a Twig solution also? just opened https://craftcms.stackexchange.com/questions/36514/craft-3-twig-search-query-for-entry-with-custom-entriesfield-containing-disabl  

---

### Answer by username_4 on 2016-07-27. Score: 2

To pull both enabled and disabled entries from an Entries field, you can do this:
$entry->entriesField->status = 'any';
$relatedEntries = $entry->entriesField->find();


---

### Answer by username_5 on 2016-07-27. Score: 1

Related fields will always ignore disabled entries.

Instead of disabling entries, you could add a lightswitch field to your entries to indicate whether or not they are disabled. This would preserve relations to those entries and would return all entries, regardless of the value of the lightswitch field.

When fetching entries in other circumstances, if you only wanted to show enabled entries, you would need to always need to explicitly include a condition that the lightswitch was on (`=='1'`).

> **Comments:**
> **username_0**: Thanks Steve. I'd prefer to do this without querying the DB for the disabled entry, so if you're right, then this is what I'll have to do as a workaround.  
> **username_5**: It's the easiest way to handle it. I've used a similar system on a site I've built recently and it works really well. As far as I know, it's the only way to keep relations live whilst disabling direct access to entries that are the target of those relations.  

---

