0

I'm new in wordpress. I want to display all author list with its ID. I'm using wp_list_authors function but didn't get any author id from the author list. So, How can I get Author's ID in listing of all author?

2

You can use the following:

// prepare arguments
$args  = array(
// search only for Authors role
'role' => 'Author',
// order results by display_name
'orderby' => 'display_name'
);
// 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.

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.