<p>You’d first get all the relevant entries of your “trainings” section, or better get just their IDs as that’s way better on performance.
Then on another element query you set the <code>relatedTo</code> parameter to only get entries related to these entry IDs.</p>

<pre><code>{% set trainingsEntriesIds = craft.entries({
    section: 'trainings',
    postDate: '&gt;= ' ~ 'now'|date('c'),
}).ids() %}

{% set entries = craft.entries({
    section: 'locations',
    relatedTo: {
        targetElement: trainingsEntriesIds,
        field: 'entriesFieldHandle'
    },
}).all() %}
</code></pre>

CC BY-SA 3.0
2018-01-31T15:37:25.953Z
2018-01-31T15:48:59.037Z
2018-01-31T15:48:59.037Z
carlcs
<p>Does anyone know how to achieve the following in Twig with Craft 3:</p>

<p>My sections
<strong>locations</strong> and <strong>trainings</strong>.</p>

<p>I want to find all the entries from <strong>locations</strong> which has a relation to <strong>trainings</strong> and a datetime field value from <strong>trainings</strong> has to be after now.</p>

<entries><relations><craft3>
Find entries from related section after certain date
# Find entries from related section after certain date

(Asked by: username_0 on 2018-01-31)

Does anyone know how to achieve the following in Twig with Craft 3:

My sections
**locations** and **trainings**.

I want to find all the entries from **locations** which has a relation to **trainings** and a datetime field value from **trainings** has to be after now.

**Tags:** entries, relations, craft3

---

## 1 answers

### Answer by username_1 on 2018-01-31. Score: 4 | Accepted answer

You’d first get all the relevant entries of your “trainings” section, or better get just their IDs as that’s way better on performance.
Then on another element query you set the relatedTo parameter to only get entries related to these entry IDs.
{% set trainingsEntriesIds = craft.entries({
    section: 'trainings',
    postDate: '>= ' ~ 'now'|date('c'),
}).ids() %}

{% set entries = craft.entries({
    section: 'locations',
    relatedTo: {
        targetElement: trainingsEntriesIds,
        field: 'entriesFieldHandle'
    },
}).all() %}


---

