My blog have many author. I can list all author.

All Author list:

<?php wp_list_authors('exclude_admin=0&optioncount=1&show_fullname=1&hide_empty=1'); ?>

But I want to sort in a special way.

For Example im currently viewing Tech category page, I want a list of author with these id (3,10,12). I will use this code in sidebar widget. And i need a metabox for select author id.



I assume that you would be providing the author IDs in the widget options. And that the authors would be displayed in the order they were listed.

Assuming the input would be -> 3,10,12

You can have the following code to display the authors with that user ID in that order:

$user_ids = "3,10,12"; //this is assuming you already have the value stored in a variable

//convert the comma separated string into an array
$user_ids_array = explode(",", $user_ids);

//display the list of users
echo '<ul>';
foreach( $user_ids_array as $id ):
    $user = get_userdata( $id );
    echo '<li>'.$user->ID.' '.$user->display_name.'</li>';
echo '</ul>';
| improve this answer | |

You can use the following:

    // prepare arguments
    $args  = array(
    // search only for Authors role
    'role' => 'Author',
    // order results by display_name
    'orderby' => 'display_name'

//add your custom meta key query here

    // Create the WP_User_Query object
    $wp_user_query = new WP_User_Query($args);
    // Get the results
    $authors = $wp_user_query->get_results();
    // Check for results
    if (!empty($authors))
        echo '<ul>';
        // loop trough each author
        foreach ($authors as $author)
            // get all the user's data
            $author_info = get_userdata($author->ID);
            echo '<li>'.$author->ID.' '.$author_info->first_name.' '.$author_info->last_name.'</li>';
        echo '</ul>';
    } else {
        echo 'No authors found';

For more reference see this.

| improve this answer | |
  • Hello, thnx for answer but i need custom solution. i don't know very good PHP. – Genxer Jan 17 '13 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.