<p>This should do it:</p>

<pre><code>{# Grab all the entries for the section #}
{% set entries = craft.entries.section('news').find() %}

{# Group by the authorId #}
{% set entriesByAuthor = entries|group('authorId') %}

{# Grab all of the users with the userIds in entriesByAuthor #}
{% set authors = craft.users.id(entriesByAuthor|keys) %}

&lt;ul&gt;
    {% for author in authors %}
        &lt;li&gt;{{ author.username }}
    {%  endfor %}
&lt;/ul&gt;
</code></pre>

CC BY-SA 3.0
2014-08-21T14:42:17.077Z
Awesome, thanks as always!! Why doesn't it work with the usual relatedTo parameter?
Alan Miller
CC BY-SA 3.0
2014-08-21T04:40:44.997Z
2018-01-29T17:51:14.637Z
2018-01-29T17:51:14.637Z
Brad Bell
<p>This is similar to <a href="https://craftcms.stackexchange.com/questions/1345/check-to-see-if-category-is-populated">another question</a>, and should yield the same results:</p>

<pre><code>{% set entryIds = craft.entries.section('news').ids() %}
{% set authorList = craft.users.relatedTo({ sourceElement: entryIds }).find() %}
</code></pre>

<p>With this you are basically saying, "I'm looking for users related to these news entries where the news entry is where the user is set".</p>

CC BY-SA 3.0
2014-07-24T13:07:24.353Z
I tried a version like that previously and I also just tested the snippet above and it isn't working : ( That is definitely how I would expect it to work... that's why I thought maybe there was something I was missing.
Alan Miller
CC BY-SA 4.0
2020-06-04T03:53:39.983Z
This only works with a user relationship field on the entry, or a entries relationship field on the user. This does not work for the Author field on entries.
Johan Douma
CC BY-SA 3.0
2014-07-24T12:53:38.853Z
2014-07-24T12:53:38.853Z
2017-04-13T12:51:00.303Z
Bryan Redeagle
<p>I am trying to show a list of users but only if they have created a post in a certain section... the code I am using isn't working as expected. Perhaps I have the syntax wrong when it comes to the user model</p>

<p>Help would be greatly appreciated.</p>

<pre><code>{% set entries = craft.entries.section('news') %}
{% set authorList = craft.users.relatedTo(entries) %}

{% for author in authorList %}
&lt;h5&gt;&lt;a href="/news/author/{{author.username}}"&gt;{{author.fullName}}&lt;/a&gt;&lt;/h5&gt;
{% endfor %}         
</code></pre>

<users>
Author List, Only Users With Entry
# Author List, Only Users With Entry

(Asked by: username_0 on 2014-07-24)

I am trying to show a list of users but only if they have created a post in a certain section... the code I am using isn't working as expected. Perhaps I have the syntax wrong when it comes to the user model
Help would be greatly appreciated.
{% set entries = craft.entries.section('news') %}
{% set authorList = craft.users.relatedTo(entries) %}

{% for author in authorList %}
{{author.fullName}}
{% endfor %}

**Tags:** users


---

## 2 answers

### Answer by username_1 on 2014-08-21. Score: 2 | Accepted answer

This should do it:
{# Grab all the entries for the section #}
{% set entries = craft.entries.section('news').find() %}

{# Group by the authorId #}
{% set entriesByAuthor = entries|group('authorId') %}

{# Grab all of the users with the userIds in entriesByAuthor #}
{% set authors = craft.users.id(entriesByAuthor|keys) %}


    {% for author in authors %}
        {{ author.username }}
    {%  endfor %}

> **Comments:**
> **username_0**: Awesome, thanks as always!! Why doesn't it work with the usual relatedTo parameter?  

---

### Answer by username_2 on 2014-07-24. Score: 1

This is similar to another question, and should yield the same results:
{% set entryIds = craft.entries.section('news').ids() %}
{% set authorList = craft.users.relatedTo({ sourceElement: entryIds }).find() %}

With this you are basically saying, "I'm looking for users related to these news entries where the news entry is where the user is set".

> **Comments:**
> **username_0**: I tried a version like that previously and I also just tested the snippet above and it isn't working : ( That is definitely how I would expect it to work... that's why I thought maybe there was something I was missing.  
> **username_3**: This only works with a user relationship field on the entry, or a entries relationship field on the user. This does not work for the Author field on entries.  

---

