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!


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',
}) %}
  • 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
    Apr 3 '17 at 14:49
  • Sure, I just updated the answer.
    – carlcs
    Apr 3 '17 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.