Get an array of all authors (2 posts)

  1. Justin Tadlock

    Posted 7 years ago #

    I need to get an array of all author's of a blog.

    Here's the code I have in mind, unless there's some WP function I should know about.

    function op_all_authors() {
    	$all_authors = AN ARRAY OF AUTHORS
    	foreach($all_authors as $key => $value) {
    		$all_authors[$key] = $all_authors[$key];
    	return $all_authors;

    Basically, I want to put these authors in a form select for an administrator to choose from. The author posts that's chosen will be displayed on a certain page.

    I just need to get an array of authors; I can do the rest from there.

  2. Justin Tadlock

    Posted 7 years ago #

    Nevermind, I think I got it. So, if anyone's interested, this should work:

    //Gets an array of the available authors
    function op_all_authors() {
    	global $wpdb;
    	$order = 'user_nicename';
    	$user_ids = $wpdb->get_col("SELECT ID FROM $wpdb->users ORDER BY $order");
    	foreach($user_ids as $user_id) :
    		$user = get_userdata($user_id);
    		$all_authors[$user_id] = $user->display_name;
    	return $all_authors;

Topic Closed

This topic has been closed to new replies.

About this Topic