Support » Fixing WordPress » Get an array of all authors

  • Justin Tadlock

    (@greenshady)


    WordPress God

    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.

Viewing 1 replies (of 1 total)
  • Justin Tadlock

    (@greenshady)

    WordPress God

    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;
    	endforeach;
    	return $all_authors;
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Get an array of all authors’ is closed to new replies.