Body: <p>I have 2 channels, "events" and "venues". Using the entries fieldtype in the "event" entry a "venue" where it takes place is selected. However, if the venue entry is disabled, rather than the event not showing, a fatal error kills my page.</p>
  
  <p>Is there a way of somehow querying events that doesn't return entries linked to disabled venues? I'm guessing doing something with relatedTo but not sure how to go about it.</p>
  
  <pre><code>{% set qDisplay = craft.request.getParam('display') %}
  {% set qFilter = craft.request.getParam('filter') %}
  
  {% if qDisplay == 'all' %}
  
      {% paginate craft.entries.section('events').status('live,pending').order('postDate asc') as entries %}
  
  {% elseif qDisplay == 'month' and qFilter != null %}
  
      {% set startDate = now | date_modify('first day of ' ~ qFilter) %}
      {% set endDate = startDate | date_modify('+ 1 month') %}
      {% set entries = craft.entries.section('events').postDate('&gt;= ' ~ startDate).expiryDate('&lt; ' ~ endDate).status('live,pending,expired').order('postDate asc') %}
  
  {% elseif qDisplay == 'venue' and qFilter != null %}
  
      {% set entries = craft.entries.section('events').relatedTo(qFilter).status('live,pending').order('postDate asc') %}
  
  {% else %}
  
      {% paginate craft.entries.section('events').status('live,pending').order('postDate asc') as entries %}
      {# set entries = craft.entries.section('events').status('live,pending').limit(6).order('postDate asc') #}
  
  {% endif %}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-02-29T18:18:00.153Z
Comments.Text: What's the fatal error?  Can you share the code you're using?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-01T09:18:19.177Z
Comments.Text: Updated with code example. When I say "fatal error" I just mean a twig error that kills the page. Its just because it expects some variables but can't get them from a null value.
Comments.UserDisplayName: Shealan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-01T14:59:31.510Z
Comments.Text: Do you have any idea at which line the 'fatal error' is triggered? And do you have devMode enabled? This should give you some debug.
Comments.UserDisplayName: Maarten de Graaf
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-01T15:14:48.643Z
Comments.Text: There's no mystery really, I'm just trying to understand how to write a entry query like: get * events where event.status = live && event.venue.status = live.
Comments.UserDisplayName: Shealan
Tags: <entries><relations>
Title: Events pages that are linked to venues crash when the venue entry is disabled
ThreadText: # Events pages that are linked to venues crash when the venue entry is disabled
  
  (Asked by: username_0 on 2016-02-29)
  
  I have 2 channels, "events" and "venues". Using the entries fieldtype in the "event" entry a "venue" where it takes place is selected. However, if the venue entry is disabled, rather than the event not showing, a fatal error kills my page.
  
  Is there a way of somehow querying events that doesn't return entries linked to disabled venues? I'm guessing doing something with relatedTo but not sure how to go about it.
  
  ```
  {% set qDisplay = craft.request.getParam('display') %}
  {% set qFilter = craft.request.getParam('filter') %}
  
  {% if qDisplay == 'all' %}
  
      {% paginate craft.entries.section('events').status('live,pending').order('postDate asc') as entries %}
  
  {% elseif qDisplay == 'month' and qFilter != null %}
  
      {% set startDate = now | date_modify('first day of ' ~ qFilter) %}
      {% set endDate = startDate | date_modify('+ 1 month') %}
      {% set entries = craft.entries.section('events').postDate('>= ' ~ startDate).expiryDate('< ' ~ endDate).status('live,pending,expired').order('postDate asc') %}
  
  {% elseif qDisplay == 'venue' and qFilter != null %}
  
      {% set entries = craft.entries.section('events').relatedTo(qFilter).status('live,pending').order('postDate asc') %}
  
  {% else %}
  
      {% paginate craft.entries.section('events').status('live,pending').order('postDate asc') as entries %}
      {# set entries = craft.entries.section('events').status('live,pending').limit(6).order('postDate asc') #}
  
  {% endif %}
  
  ```
  
  **Tags:** entries, relations
  
  > **Comments:**
  > **username_1**: What's the fatal error?  Can you share the code you're using?  
  > **username_0**: Updated with code example. When I say "fatal error" I just mean a twig error that kills the page. Its just because it expects some variables but can't get them from a null value.  
  > **username_2**: Do you have any idea at which line the 'fatal error' is triggered? And do you have devMode enabled? This should give you some debug.  
  > **username_0**: There's no mystery really, I'm just trying to understand how to write a entry query like: get * events where event.status = live && event.venue.status = live.  
  
  ---
  
  ## 0 answers
  
  