We know from the docs that you can get an author's meta like so:
<?php get_the_author_meta( $field, $userID ); ?>
But I would like to have a custom "About us" page which displays all the information of users with a specific role (admins and writers in this case).
Let's say I have a function (which uses custom fields of the profile) in functions.php
like so:
<?php function the_author_box($userid) { ?>
<div class="author-header clear">
<div class="author-avatar-wrap"><?php echo get_avatar($userid); ?></div>
<h4 class="author-name"><?php the_author_meta('display_name',$userid); ?></h4>
</div>
<div class="author-description">
<p><?php the_author_meta('description',$userid); ?></p>
</div>
<ul class="author-meta">
<?php if (get_the_author_meta('url',$userid)) { ?>
<li class="url">
<a href="<?php the_author_meta( 'url',$userid ); ?>" title="De website van <?php the_author_meta( 'display_name',$userid ); ?>">Website</a>
</li>
<?php if (get_the_author_meta('twitter',$userid)) { ?>
<li class="twitter">
<a href="http://twitter.com/<?php the_author_meta( 'twitter',$userid); ?>" title="Volg <?php the_author_meta( 'display_name',$userid); ?> op Twitter">Twitter</a>
</li>
</ul>
</div>
<?php } ?>
I am guessing I can get all the user IDs with get_users
. I do not need to get all the roles at the same time, so I can first get all the admins and then all the writers.
$admins = get_users('role=administrator&fields=ID');
$writers = get_users('role=author&fields=ID');
And then call the function:
<?php
foreach ($admins as $user) {
the_author_box($user);
}
foreach ($writers as $user) {
the_author_box($user);
}
?>
After testing, it seems that only the author of the page is called or the first profile in the loop. My profile ID (alphabetically the first one, and also the author of that page) is put in the function, but the others are not.
- I only want a user to be displayed once
- Other profiles should be returned as well, but they don't seem to be put in a loop