Getting Wordpress Blog Authors in Combobox

shabbir's Avatar author of Getting Wordpress Blog Authors in Combobox
This is an article on Getting Wordpress Blog Authors in Combobox in Content Management System.

Introduction



I expected wordpress to have some built in support for listing all authors of the blog in a select box but that is not the case yet in Wordpress 2.9.2.

I was certain that I can get this done using wp_list_authors but actually it was a not that straight forward and so let me share this with you. I think this will help those looking for such functionality.

The Code



What I did is replaced the content of list items ( <li> ) into select box options ( <option> ) and added a JavaScript function to redirect user to the url when there is a change in the selection in the selection box.

So here is the code.
Code:
<select id="AuthorList" name="AuthorList" onchange="goAuthorList();">
	<?php 
	$authargs = array(
		'optioncount'   => false, 
		'exclude_admin' => false, 
		'show_fullname' => false,
		'hide_empty'    => true,
		'echo'          => false, // We will not output using the function.
		'feed'          => false, 
		'feed_image'    => false,
		'style'         => 'list',
		'html'          => true 
	); 
	$var_list = wp_list_authors( $authargs ); // Take the output into a variable.
	// Replace the tags of list to option box
	$var_list = str_replace("</a></li>","</option>",$var_list); 
	$var_list = str_replace("<li><a href=","<option value=",$var_list);
	// Now output the list
	echo $var_list;	
	?> 
</select>
<script language="JavaScript">
<!--
    function goAuthorList() {
	// JavaScript function to change the user to the url of the author
		theSelAuthor = document.getElementById("AuthorList").value;
			if ("" != theSelAuthor) location.href = theSelAuthor;
    }
//-->
</script>
Enjoy !!!
0
hanleyhansen's Avatar, Join Date: Jan 2008
Pro contributor
Cool!
0
pankaj.sea's Avatar, Join Date: Apr 2009
Pro contributor
Nice Info!
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
If you like this this article nominate it for Article of the month - Mar 2010
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Vote for this article for Article of the month - Mar 2010
0
johnny.dacu's Avatar, Join Date: Jul 2010
Contributor
Why to list authors in a select? What's wrong with a list style?
0
rohan123's Avatar, Join Date: Apr 2011
Light Poster
Very Informative.
Thanks.
0
contusvideo's Avatar
Banned
Really nice info, Good contributory share @ shabbir!