Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Set up arguments for query.
- $args = [
- 'has_published_posts' => [ 'page' ],
- 'orderby' => 'post_count',
- 'order' => 'DESC',
- ];
- // Create the WP_User_Query object
- $user_query = new WP_User_Query( $args );
- // Get results.
- $users = $user_query->get_results();
- // Check for results
- if ( ! empty( $users ) ) {
- echo '<ul>' . PHP_EOL;
- // Loop through each author.
- foreach ( $users as $user ) {
- // Get all the user's data.
- $user_info = get_userdata( $user->ID );
- echo "t" . '<li>' .
- '<em>' . __( 'User ID: ', 'text-domain' ) . esc_html( $user->ID ) . '</em> ' .
- esc_html( $user_info->first_name ) . ' ' .
- esc_html( $user_info->last_name ) .
- '</li>' . PHP_EOL;
- }
- echo '</ul>' . PHP_EOL;
- } else {
- echo __( 'No authors found', 'text-domain' );
- }
Add Comment
Please, Sign In to add comment