Filtering a pagelist based on a express page attribute

I have a express entity page attribute on a page and would like to filter a pagelist on that page by the express page attribute. but can’t work it out.

Here is the setup:

I have a load of pages assigned to an Author express entity. I would then like to be able to go to an author page and have a pagelist that pulls in only pages from that Author. This page has the author page attribute added to it also as this is how I am pulling in the author bio.

I still couldn’t get this so in the end i just added a if statement inside my page for loop.

So now I get the value of the author for the page and then I loop through and see if that value is the same for each page.

I feel this is a little hacky as i can’t add pagination and every time I am looping through all the pages. then only displaying a few.

If anyone has another way to do this I am all ears?

If you want filter page list by a specific Express attribute (fetched from current page attribute), you can do something like that:

/**
 * @var \Concrete\Core\Entity\Attribute\Value\Value\ExpressValue $author
 * @var \Concrete\Core\Entity\Express\Entry $authorEntry
 * @var \Concrete\Core\Page\Page[] $pages
 */

$authorEntryID = null;
$author = $c->getAttribute('author');
if (!empty($author) && is_object($author->getSelectedEntries()[0])) {
    $authorEntry = $author->getSelectedEntries()[0];
    $authorEntryID = $authorEntry->getID();
}

$pages = [];
if ($authorEntryID) {
    $list = new \Concrete\Core\Page\PageList();
    $list->filterByAttribute('author', $authorEntryID);
    $pages = $list->getResults(); // or just paginate it
}

foreach ($pages as $page) {
    echo $page->getCollectionName() . ' | ';
    echo $page->getAttribute('author') . '<br>';
}

This is great thank you.