This code creates a page template which you can use to display any users using any of the parameters included in the get_users function.
In this example, the code generates a list of all users who have published at least 1 post however you can change the parameters to anything you like.
Installation Instructions
Simply create a new file using a code editor like Notepad++ and add the following code to the file. Save the file as a PHP file.
Name the file anything you like, ( something like page_contributors.php ) and upload it to your child themes root directory.
Hi there Brad, thank you for sharing this. I’m trying to add a piece of code that it only finds contributors for a custom post type called ‘article’. To count only articles posted and not blog ‘posts’. Can you advise me on how to do this?
I tried adding ‘post_type’ => ‘article’, to the $contributor_ids array but then got stuck as I don’t know much about customising like this.
Thanks,
Cathie.
Hi Cathie
1. There is no $post_type parameter for get_users or WP_User_Query so that won’t work.
Should be added as an enhancement to the WordPress core.
2. The good news is the code also includes a secondary function named count_users_posts which now supports post types since WordPress 4.1 was released.
See this line in the template around line 17:
Simply add your post type as the second parameter by replacing $post_type with the name of your custom post type:
This is what you will need:
Hi Brad,
I’m trying to do this in a widget, basically to create a section on my home page. How can I modify the code to achieve that?
I’m also wanting to show name (linked to author archive), avatar, bio and 3-4 images (which I’d like to add as custom profile fields). I can figure that out, though any tips or pitfalls to watch out for would be helpful.
I don’t think the output would be any different in a widget but you could change the hook from
genesis_entry_content
Another option is to modify the genesis featured widgets query $args and use that as a users widget. http://wpsites.net/best-plugins/custom-genesis-featured-posts-widget-you-can-modify-safely/
I could just take the function
contributors_author_list
and turn it into a shortcode and use that, no? (forgive me if that’s a dumb question :))Good idea of you want it within the content using the WP Editor.