Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-26T09:46:14.663Z
Answers.Text: This sounds perfect. Nice one.
Answers.UserDisplayName: Clive Portman
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-28T15:52:04.080Z
Answers.Text: Just what I was looking for. Thanks!
Answers.UserDisplayName: Cavell Blood
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-29T14:08:44.857Z
Answers.Text: 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
Answers.UserDisplayName: Kevon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-24T22:20:26.530Z
Answers.LastActivityDate: 2018-02-24T22:20:26.530Z
Answers.UserDisplayName: Chase Giunta
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-27T14:03:16.770Z
Answers.LastActivityDate: 2016-07-27T14:28:04.953Z
Answers.LastEditDate: 2016-07-27T14:28:04.953Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-27T10:24:33.050Z
Answers.Text: 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.
Answers.UserDisplayName: Clive Portman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-27T10:27:25.897Z
Answers.Text: 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.
Answers.UserDisplayName: Steve Rowling
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-27T10:22:31.037Z
Answers.LastActivityDate: 2016-07-27T10:22:31.037Z
Answers.UserDisplayName: Steve Rowling
Body: <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>
  
Tags: <plugin-development><relations>
Title: Get disabled related entry's data within plugin
ThreadText: # 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 username_5. 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.  
  
  ---
  
  