Multiple authors on a single post

Hello,

What is the best way to achieve this?

I’ve been trying to implement this with @distantnative’s Multi Select (https://github.com/distantnative/multiselect) by making an “authors-api” template to collect all users and return them as a JSON object for the field to work with but I’m stuck while trying to build the JSON.

The $site->users() variable returns a collection with only linebreaks such as:

admin<br />user1<br />user2

$site->users()->toJson() should create the JSON array you need … https://getkirby.com/docs/cheatsheet/users/to-json

Thank you! I tried that one before but kept getting errors. I ended up populating an array by myself, like this:

<?php
header('Content-type: application/json; charset=utf-8');

$data = kirby()->site()->users()->toArray();
$json = array();
foreach($data as $username) {
	$json[$username->username()] = $username->username();
}
echo json_encode($json);
?>

Forgot I had to see each user as an object. It must have been very late…

Hi Roy. Wanted to try your field just for kicks but it didn’t seem to work:

Hey @invasoria, whats the solution you have come up with?

I remotely created a JSON output with the users array code I mentioned earlier in this thread (Multiple authors on a single post). That way I fetched each user and populated the Multiselect box, through the JSON API function.

Take a look at the Dynamic options via JSON API section:
https://getkirby.com/docs/cheatsheet/panel-fields/select

The Controlled List plugin might be an alternative to using the JSON Query API

1 Like

Yes! I was just looking at that plugin and was going to edit this post. As always, faster than lightning Sonja! :smile:

1 Like