我想检索12个Wordpress用户的列表,但我想让他们随机(在每个页面重新加载时)并且只有12个指定了Gravatar的用户。
现在,我有12个随机用户,但我不能只检索那些带有Gravatar的用户。。。你能帮帮我吗?
以下是我现在拥有的:
功能。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;
}
在我的模板中:
<?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>
提前谢谢你,塞德里克