wordpress - How to display random 10 authors with their avatars? -


i using code below, display author's avatars of blog on wordpress webpage. however, display 10 random avatars, not od them. there way without using plugin?

$blogusers = get_users_of_blog(); if ($blogusers) {     foreach ($blogusers $bloguser) {         $user = get_userdata($bloguser->user_id);         echo get_avatar( $user->id, 70 );      } } 

get_users_of_blog deprecated. use get_users instead:

https://codex.wordpress.org/function_reference/get_users

using get_users alone, cannot random users, can use pre_user_query action update order by clause in sql:

// update query order random function randomize_users(&$query) {     $query->query_orderby = "order rand()"; }  // attach function pre_user_query hook add_action( 'pre_user_query', 'randomize_users' );  // users $users = get_users(array(     'blog_id' => get_current_blog_id(),     'number' => 10 ));  // remove action future queries won't affected remove_action( 'pre_user_query', 'randomize_users' ); 

source: https://core.trac.wordpress.org/ticket/20606


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -