views:

140

answers:

2

Hey,

I want wordpress to give me an array that contains all authors. There are some dumb functions, that echo html (wp_list_authors()) - but that's not what I want.

I want to get the full profile (ID, name, meta-data).

My current approach isn't, what I am looking for - to be exact, it's **it.

$authors = wp_list_authors(array(
'optioncount'   => false, 
'exclude_admin' => false, 
'show_fullname' => false,
'hide_empty'    => false,
'echo'          => false,
'html'      => false)
);
$authors = explode(", ", $authors);

And even here I am stuck, since there is no get_author_id_by_name() or similar.

Please help, I don't want to do SQL in a friggin template.

A: 

Well, if you know the user ID, you can use get_userdata.

Otherwise you should take a look at this suggestion: http://wpengineer.com/list-all-users-in-wordpress/

Steven
A: 
global $wpdb;
$allAuthorIds = $wpdb->get_column( "SELECT ID FROM {$wpdb->users}" );
$authorsInfo = array();
foreach( $allAuthorIds as $authorId ) {
  $authorsInfo[$authorId] = get_userdata($authorId);
}

That will give the info for every single user (including WP extended info) in the $authorsInfo array. If you need to get users by their role ('author') then you should use the WP_User_Search class. You're pretty much forced to use SQL here and there is nothing wrong with that.

nickohrn
its not good style imo, but weeell.. anyways ^.^ thanks I'll give it a try
Jänz
If anyone uses the above code: make sure to use "$authorId->ID" instead of "$authorId" for get_userdata.
Jänz
Oops, sorry about that. Edited to correct.
nickohrn