tools/wordpress-user-query-generator
WordPress User Query Generator
Build a WP_User_Query call: filter by role, meta or a wildcard search, choose what the query returns, and get a loop that matches it — without paying for a total count you never read.
snippet.php
$args = array(
'role' => 'author',
'orderby' => 'display_name',
'order' => 'ASC',
'number' => 10,
'count_total' => false,
);
$user_query = new WP_User_Query( $args );
// get_results() rather than a ->results property: WP_User_Query exposes the
// matches through this method, and it is what returns the shape 'fields' asked
// for.
$users = $user_query->get_results();
if ( ! empty( $users ) ) {
echo '<ul>';
foreach ( $users as $user ) {
printf(
'<li><a href="%s">%s</a></li>',
esc_url( get_author_posts_url( $user->ID ) ),
esc_html( $user->display_name )
);
}
echo '</ul>';
} else {
printf( '<p>%s</p>', esc_html__( 'No users found.', 'text-domain' ) );
}