<p>You first need to query for all post entries and then query for the authors that are related to a post. You can use the <code>ids()</code> method to get just the author’s element IDs, which is a lot quicker than <code>find()</code>.</p>

<pre><code>{% set allPostIds = craft.entries({
    section: 'posts',
    limit: null,
}).ids() %}

{% set people = craft.entries({
    section: 'people',
    relatedTo: {
        sourceElement: allPostIds,
        field: 'people',
    },
}) %}
</code></pre>

CC BY-SA 3.0
2017-04-03T14:49:32.797Z
Great, but to confuse matters I have two People entry fields: Authors and People - I only want to match authors... any idea how I could do that?
Daniel
CC BY-SA 3.0
2017-04-03T15:04:34.253Z
Sure, I just updated the answer.
carlcs
CC BY-SA 3.0
2017-04-03T12:37:33.893Z
2017-04-03T15:03:58.527Z
2017-04-03T15:03:58.527Z
carlcs
<p>I have a section <code>Posts</code> that has an Entries-type field called <code>Authors</code> that can be linked to one or more entries in section called <code>People</code>. To make a filter for my posts index, I need to fetch all the <code>People</code> entries that have been linked to any post via the Authors field, but I can't wrap my head around how to do this.</p>

<p>Any ideas appreciated!</p>

<relatedto>
Fetch target entries that have been linked through an Entries field
# Fetch target entries that have been linked through an Entries field

(Asked by: username_0 on 2017-04-03)

I have a section `Posts` that has an Entries-type field called `Authors` that can be linked to one or more entries in section called `People`. To make a filter for my posts index, I need to fetch all the `People` entries that have been linked to any post via the Authors field, but I can't wrap my head around how to do this.

Any ideas appreciated!

**Tags:** relatedto


---

## 1 answers

### Answer by username_1 on 2017-04-03. Score: 4 | Accepted answer

You first need to query for all post entries and then query for the authors that are related to a post. You can use the ids() method to get just the author’s element IDs, which is a lot quicker than find().
{% set allPostIds = craft.entries({
    section: 'posts',
    limit: null,
}).ids() %}

{% set people = craft.entries({
    section: 'people',
    relatedTo: {
        sourceElement: allPostIds,
        field: 'people',
    },
}) %}

> **Comments:**
> **username_0**: Great, but to confuse matters I have two People entry fields: Authors and People - I only want to match authors... any idea how I could do that?  
> **username_1**: Sure, I just updated the answer.  

---

