How to create list of links to choosen WP authors?

If you’d like to list only choosen authors, ACF module may be great help. Pro version contains “Repeater field” that allows admin to add and easily change order of unlimited items. One of standard field types is called “User” – this one allows admin to choose one of registered users and returns it’s array. User ID can be used to get author URL.

ACF repeater setup, User field type

ACF repeater setup, User field type

 

Example of array returned by get_field(‘authors-link’,’options’) for config from the screenshot:
[php]
Array(
[ID] => 127
[user_firstname] => John
[user_lastname] => Doe
[nickname] => John Doe
[user_nicename] => john-doe
[display_name] => John Doe
[user_email] => j-doe@gmail.com
[user_url] =>
[user_registered] => 2011-09-28 08:13:54
[user_description] =>
[user_avatar] =>
)
[/php]
To get author link, simply use get_author_posts_url function. In that case, it will look like this:

[php]
$author = get_sub_field(‘authors-link’,’options’);
echo get_author_posts_url($author[ID]);
[/php]

Leave a Reply

Your email address will not be published. Required fields are marked *