I am trying to order some data by 'rand' on a foreach loop I have created which is outputting some users which I have created a custom role for. all the other bits are great apart from this.
This is the current state of the loop:
<?php
// Featured Consultants
$consultants = get_users( 'role=consultant&number=2' );
// Array of WP_User objects.
foreach ( $consultants as $consultant ) {
// Check for 'featured' Consultants
if($consultant->featured == 'Yes'){
echo '<div class="columns six consultantCard">';
echo '<div class="columns four">';
echo get_avatar( $consultant->id, 150 );
echo '</div>';
echo '<div class="columns eight">';
// Get users details
echo '<span class="name">' . esc_html( $consultant->first_name ) . ' ' . esc_html( $consultant->last_name ) . '</span>';
echo '<span class="jobTitle">' . esc_html( $consultant->job_title ) . '</span>';
echo '<span class="location">Currently based in ' . esc_html( $consultant->current_location ) . '</span>';
// Check if user is less than 30 days old
if( strtotime($consultant->user_registered) < strtotime('30 days') ){
echo '<span class="newTag">New</span>';
}
// Check if user is featured
if($consultant->featured == 'Yes'){
echo '<span class="featuredTag">Featured Candiate</span>';
}
// Check if user is accredited
if($consultant->accredited == 'Yes'){ ?>
<span class="icon"><img src="<?php bloginfo('template_url');?>/assets/img/icons/accreditedIcon.png" /></span>
<?php echo '<span class="accreditedTag">Bench Accredited</span>';
}
echo '</div>';
echo '</div>';
} else{
echo 'No Featured Consultants';
}
}
?>
It just appears to be showing the latest entries and nothing more. I tried to also create an array but still the same result like so:
$consultant = array(
'role' => 'consultant',
'order' => 'rand'
);