I would like to retrieve a list of 12 WordPress users, but I would like to have them randomly (at each page reload) AND only 12 users that have a Gravatar specified.
Right now, I have my 12 random users, but I can’t only retrieve those with a Gravatar…
Could you help me ?
Here is what I have right now :
Functions.php :
// ***********************************************************************************
// ******* Random users
// ***********************************************************************************
add_action( 'pre_user_query', 'my_random_user_query' );
function my_random_user_query( $class ) {
if( 'rand' == $class->query_vars['orderby'] )
$class->query_orderby = str_replace( 'user_login', 'RAND()', $class->query_orderby );
return $class;
}
In my template :
<?php $args = array(
'role' => '',
'meta_key' => '',
'meta_value' => '',
'meta_compare' => '',
'meta_query' => array(),
'include' => array(),
'exclude' => array(),
'orderby' => 'rand',
'offset' => '',
'search' => '',
'number' => '12',
'count_total' => false,
'fields' => 'all',
'who' => ''
);
$users = get_users($args);
?>
<ul class="you-know-people cf">
<?php $i=0; ?>
<?php foreach ( $users as $user ) { ?>
<?php $author_avatar = get_avatar($user->ID,55); ?>
<li class="you-know-people-item <?php if($i%4 === 0){echo 'first';}?>">
<a href="#">
<?= $author_avatar; ?>
</a>
</li>
<?php $i++; ?>
<?php }?>
</ul>
Thank you in advance,
Cédric