<p>after some tinkering chatGPT came up with a rather elegant solution:</p>
<pre><code>{# Today at midnight #}
{% set todayMidnight = now|date('Y-m-d 00:00:00') %}

{# All agenda entries from today #}
{% set entries = craft.entries.section('agenda').datumBeginn('&gt;= ' ~ todayMidnight).limit(null).all() %}

{# Use map and arrow function to get the unique user IDs #}
{% set userIds = entries|map(entry =&gt; entry.author.id)|unique %}

{# Get the users based on the user IDs #}
{% set users = craft.users().group('convivien').status('active').cf_convivien_hide('not 1').id(userIds).orderBy('username').all() %}

{# Output the list of users #}
&lt;ul&gt;
  {% for user in users %}
    &lt;li&gt;{{ user.name }}&lt;/li&gt;
  {% endfor %}
&lt;/ul&gt;
</code></pre>
<p>I quite like this solution.</p>

CC BY-SA 4.0
2023-03-02T10:24:17.483Z
2023-03-02T10:24:17.483Z
outline4
<p>I would try it this way:</p>
<p>{% set authors = craft.entries.section('agenda').datumBeginn('&gt;= ' ~ todayMidnight).select(['author']).all() %}</p>
<p>Authors should be a list of user ids.</p>
<p>Credit to an older post:
<a href="https://craftcms.stackexchange.com/questions/38471/get-array-of-titles-instead-of-whole-collection-of-entries-attributes">Get array of titles instead of whole collection of entries&#39; attributes</a></p>

CC BY-SA 4.0
2023-03-02T09:44:46.937Z
Hi, when I use `{% set authors = craft.entries.section('agenda').datumBeginn('>= ' ~ todayMidnight).select(['authorId']).asArray().limit(null).all() %}`it returns a list of author Id's. But that still leaves me with duplicates and no author names.
outline4
CC BY-SA 4.0
2023-03-02T16:09:09.580Z
You can use array_unique() on the array and then call `craft.users.id(authors).orderBy('firstName').all` that will give you the list of users or you can do a similar `.select(['fullName'])` if you just want an array of names
cherrykoda
CC BY-SA 4.0
2023-03-02T16:17:09.453Z
Technically you can pass the array including duplicates to the users query - Craft will return the users without duplicates. But I can understand feeling 'ick' about that.
cherrykoda
CC BY-SA 4.0
2023-03-03T11:04:24.420Z
ok, thanks for the clarification!
outline4
CC BY-SA 4.0
2023-03-02T05:11:22.713Z
2023-03-02T05:11:22.713Z
cherrykoda
<p>I want to list users that have created entries in a specific channel.</p>
<p>I tried it the <a href="https://straightupcraft.com/articles/how-do-i-only-display-a-list-of-categories-that-have-entries-and-hide-empty-categories" rel="nofollow noreferrer">Ben Parisak way</a>, but that didn't work out.</p>
<p>here's the code that doesn't work (example 1):</p>
<pre><code>{% set entryIds = craft.entries.section('agenda').datumBeginn('&gt;= ' ~ todayMidnight).limit(null).ids() %}
{% set convivien = craft.users()
    .group('convivien')
    .status('active')
    .cf_convivien_hide('not 1')
    .relatedTo(entryIds)
    .orderBy('firstName')
    .all()
%}
</code></pre>
<p>If I had a user field within the agenda channel it would work. But I am trying to get the authors of those entries, and apparently they are not stored as a relation. Maybe this is intentional, maybe not.</p>
<p>Anyways: the workaround I found is really messy (example 2):</p>
<pre><code>{% set entries = craft.entries.section('agenda').datumBeginn('&gt;= ' ~ todayMidnight).limit(null).all() %}
{% set convivien = [] %}
{% for entry in entries %}
    {% set author = entry.author %}
    {% if author.groups[0].name == &quot;Convivien&quot; and not convivien|filter(item =&gt; item.id == author.id)|length %}{% set convivien = convivien|merge([{'name': author.name, 'id': author.id}]) %}{% endif %}
{% endfor %}
{% set convivien = convivien|sort %}
</code></pre>
<p>if code example 1 would work I could use the same code here:</p>
<pre><code>&lt;select name=&quot;convivien&quot; id=&quot;veranstalter&quot;&gt;
    &lt;option value=&quot;&quot;&gt;{{ &quot;Kanton wählen&quot;|t }}&lt;/option&gt;
    {% for convivium in convivien %}
        &lt;option value=&quot;{{ convivium.id }}&quot;{% if convivienParam == convivium.id %} selected=&quot;selected&quot;{% endif %}&gt;{{ convivium.name }}&lt;/option&gt;
    {% endfor %}
&lt;/select&gt;
</code></pre>
<p>Does somebody know why example 1 is not working and how I could elegantly achieve this like I was Ben Parisak ;)</p>

<templating><users><array>
How do I only display a list of users that have entries and hide the rest
# How do I only display a list of users that have entries and hide the rest

(Asked by: username_0 on 2023-02-23)

I want to list users that have created entries in a specific channel.
I tried it the Ben Parisak way, but that didn't work out.
here's the code that doesn't work (example 1):
{% set entryIds = craft.entries.section('agenda').datumBeginn('>= ' ~ todayMidnight).limit(null).ids() %}
{% set convivien = craft.users()
    .group('convivien')
    .status('active')
    .cf_convivien_hide('not 1')
    .relatedTo(entryIds)
    .orderBy('firstName')
    .all()
%}

If I had a user field within the agenda channel it would work. But I am trying to get the authors of those entries, and apparently they are not stored as a relation. Maybe this is intentional, maybe not.
Anyways: the workaround I found is really messy (example 2):
{% set entries = craft.entries.section('agenda').datumBeginn('>= ' ~ todayMidnight).limit(null).all() %}
{% set convivien = [] %}
{% for entry in entries %}
    {% set author = entry.author %}
    {% if author.groups[0].name == "Convivien" and not convivien|filter(item => item.id == author.id)|length %}{% set convivien = convivien|merge([{'name': author.name, 'id': author.id}]) %}{% endif %}
{% endfor %}
{% set convivien = convivien|sort %}

if code example 1 would work I could use the same code here:

    {{ "Kanton wählen"|t }}
    {% for convivium in convivien %}
        {{ convivium.name }}
    {% endfor %}


Does somebody know why example 1 is not working and how I could elegantly achieve this like I was Ben Parisak ;)

**Tags:** templating, users, array

---

## 2 answers

### Answer by username_0 on 2023-03-02. Score: 0 | Accepted answer

after some tinkering chatGPT came up with a rather elegant solution:
{# Today at midnight #}
{% set todayMidnight = now|date('Y-m-d 00:00:00') %}

{# All agenda entries from today #}
{% set entries = craft.entries.section('agenda').datumBeginn('>= ' ~ todayMidnight).limit(null).all() %}

{# Use map and arrow function to get the unique user IDs #}
{% set userIds = entries|map(entry => entry.author.id)|unique %}

{# Get the users based on the user IDs #}
{% set users = craft.users().group('convivien').status('active').cf_convivien_hide('not 1').id(userIds).orderBy('username').all() %}

{# Output the list of users #}

  {% for user in users %}
    {{ user.name }}
  {% endfor %}


I quite like this solution.


---

### Answer by username_1 on 2023-03-02. Score: 3

I would try it this way:

{% set authors = craft.entries.section('agenda').datumBeginn('>= ' ~ todayMidnight).select(['author']).all() %}

Authors should be a list of user ids.

Credit to an older post:
[Get array of titles instead of whole collection of entries' attributes](https://craftcms.stackexchange.com/questions/38471/get-array-of-titles-instead-of-whole-collection-of-entries-attributes)

> **Comments:**
> **username_0**: Hi, when I use `{% set authors = craft.entries.section('agenda').datumBeginn('>= ' ~ todayMidnight).select(['authorId']).asArray().limit(null).all() %}`it returns a list of author Id's. But that still leaves me with duplicates and no author names.  
> **username_1**: You can use array_unique() on the array and then call `craft.users.id(authors).orderBy('firstName').all` that will give you the list of users or you can do a similar `.select(['fullName'])` if you just want an array of names  
> **username_1**: Technically you can pass the array including duplicates to the users query - Craft will return the users without duplicates. But I can understand feeling 'ick' about that.  
> **username_0**: ok, thanks for the clarification!  

---

