<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>

CC BY-SA 3.0
2016-02-29T18:18:00.153Z
What's the fatal error?  Can you share the code you're using?
Brad Bell
CC BY-SA 3.0
2016-03-01T09:18:19.177Z
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.
Shealan
CC BY-SA 3.0
2016-03-01T14:59:31.510Z
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.
Maarten de Graaf
CC BY-SA 3.0
2016-03-01T15:14:48.643Z
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.
Shealan
<entries><relations>
Events pages that are linked to venues crash when the venue entry is disabled
# 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

