wordpress snippets last updated   : October 6, 2014
we now have 641 snippets

Display list of authors in a dropdown menu using wp_dropdown_users

wordpress snippet

Adding this snippet to your wordpress template will display a list of authors within a dropdown menu linking to their author profiles. I also excluded the default user ‘1’ as the administrators would also be display. This is a comma separated list so you can remove any users that you don’t wish to display.

snippet :  PHPcopy
<li id="users">
 <h2><?php _e('users:'); ?></h2>
   <form action="<?php bloginfo('url'); ?>" method="get">
   <?php 
     $args = array(
   	 'exclude'                 => '1',
   	 'name'                    => 'authors',
   	 'who'                     => 'authors'
    );
    wp_dropdown_users($args); 
   ?>
   <input type="submit" name="submit" value="view" />
   </form>
</li>
source →

Did you like this post? If so please share it with your friends. Thanks!

  • Mike

    Kevin — maybe you can help. I’ve been searching for a couple days. I am after code to make a drop down list of POSTS. The Codex covers everything but that, which seems a strange oversight.

    I’ve found two sources, mainly the Dagon code which works but is too complex for my weak PHP skills to style (width and background color for example).

    I know that some javascript is needed to make the code dynamic, but it can’t be that complex. So, what is the magic bullet to turn a list of … anything into a drop down format? The Codex addresses pages, archives, tags, and about anything for drop downs except posts.

    Any guidance is appreciated
    Mike

    • http://wpsnipp.com Kevin Chard

      Hi Mike,
      Well this should solve your problem, http://pastebin.com/uAiujNYL
      If I could specify post_type within wp_dropdown_pages that would solve things but does not appear to work. However the code I put online at pastebin should work fine for you and nice and sample. Place that code in any location within your wordpress theme.

      • Mike

        Kevin, thank you!!! Works like a charm. NOW :), and I don’t mean to try your patience and time, but can you also tell how to add a line of javascript to make each drop down link clickable. I do have code from a site that has a permalink with a click but the problem is that there’s no –Select an item– as the first entry, the null value, so that this first item can never be used.  Need like (in the your drop down box):
        — Select an item —
        clickable item A
        clickable item B
        etc.

        Javascript is something I don’t enjoy LOL It is in no way intuitive. Anyway, this last piece will complete the puzzle. Again, I’ve played with the Dagon script but it’s too complex to alter.

        Mike

        • http://wpsnipp.com Kevin Chard

          Hi Mike ill post this as a snippet this week.

  • Jenn

    Hi there– this is great, two questions: 1. Where do I add this in my theme template? 2. How do I have it include only users with the role of “contributor”? Thanks!

  • Gunaseelan

    I have a Query. I need a dropdown list which should display users except the admin and the current user id who is logged in. How to accomplish this scenario?

  • http://senlinonline.com/ Piet

    it should actually be 'name' => 'author', (without the “s”) otherwise you will not end up on the authors profile page