WP_Query 'orderby' => 'rand' isn't working for a custom post type

Hello,

can anyone please advise why this is not working? It is just showing the same post each page refresh rather than a new random one from the list.

<?php $loop = new WP_Query( array(
'post_type' => 'testimonials',
'posts_per_page' => 1,
'orderby' => 'rand' ) );
?>

<?php while( $loop->have_posts() ) : $loop->the_post(); ?>

<div class="quote_bubble"><?php the_content(); ?></div>										

<div class="speech_bubble_credit"><?php the_field('testimonial_name'); ?><br />

<?php the_field('testimonial_job_company'); ?>, <?php the_field('testimonial_company'); ?></div>

<?php endwhile; wp_reset_query(); ?>

Open in new window


This is just displaying the first post I added to the site again and again every time page is refreshed too if that is of any use in trying to establish the problem.

Any ideas anyone please?

Thanks!
igloobobAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jason C. LevineDon't talk to me.Commented:
Where are you hosted? Some ISPs disable the rand function because it takes too many resources.
igloobobAuthor Commented:
hosted on WP Engine
Jason C. LevineDon't talk to me.Commented:
Thought so!

WP Engine does disables rand.  Log in as administrator and go to the WP Engine tab for the site.  There should be a checkbox to re-enable it.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
igloobobAuthor Commented:
Aha! Thanks that's sorted it! Thought I was going mad, as I was sure this exact loop was working on the dev version of the site before migrating to WPE!

Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
WordPress

From novice to tech pro — start learning today.