List of authors is empty

I followed the cookbook recipe for adding an authors page but it is always empty and I don’t know why. It seems to be related with the first variable but the author field exists and is set.

authors.php template:

<?php snippet('header') ?>
<?php
  // fetch all used authors emails from all articles
  $authorlist = $site->pages()->pluck('author', '-', true);
  foreach($authorlist as $author):
    echo $author; // no visible output
  endforeach;
  // get a list of all authors filtered by the ones with articles
  $authors = $kirby->users()->filterBy('id', 'in', $authorlist);
?>

<h1>Authors</h1>

<?php foreach($authors as $author): ?>
  <article class="author">
    <h1><?= $author->name() ?></h1>
    <?php if($avatar = $author->avatar()): ?>
      <figure>
        <img src="<?= $avatar->url() ?>">
      </figure>
    <?php endif ?>
    <?php if ($blog = page('blog')): ?>
      <ul class="articles">
      <?php
        // filter all articles per author
          $articles = $blog->children()->listed()->filter(function($child) use($author){
          return in_array($author->email(), $child->author()->yaml());
        });
        foreach($articles as $article): ?>
          <li><a href="<?= $article->url() ?>"><?= $article->title() ?></a></li>
        <?php endforeach ?>
      </ul>
    <?php endif ?>

  </article>
<?php endforeach ?>

<?php snippet('footer') ?>

Example content of one blog article:

Title: Example title

----

Author:

- kOBKf1Qa

----

Intro: 

----
...

pages() only gives you first level pages which probably don’t have an author?

Yes, you are right, if I add ->children() then I get a list but then the second variable ($authors) will stay empty.

What do you get if you dump($authorlist);

Array
(
[0] => kOBKf1Qa
)

Hm, that should actually work then when you do a dump($authors).

No, it is empty:

<?php
  // fetch all used authors emails from all articles
  $authorlist = $site->pages()->children()->pluck('author', '-', true);
  foreach($authorlist as $author):
    echo $author; // kOBKf1QA
    dump($authorlist); // Array ( [0] => kOBKf1QA )
  endforeach;
  // get a list of all authors filtered by the ones with articles
  $authors = $kirby->users()->filterBy('email', 'in', $authorlist);
  foreach($authors as $author):
    dump($authors); // no visible output
  endforeach;
?>

The user index.php looks like this:

<?php
return [
    'email' => 'my@email.com',
    'language' => 'de',
    'name' => 'Frederik',
    'role' => 'admin'
];

And the user.txt

Street: my street

----

Zip: my zip code

----

City: my city
...

Must be id not email.

Thanks, now it works as expected :slight_smile: