Solution to orderby=rand not working in WordPress

Tips, Wordpress 2 Comments

I had this problem while developing a custom WordPress widget for my client, it displays random testimonials with thumbnail,video and star ratings.

Below is a part of my code on the custom widget

   query_posts('post_type=testimonials&orderby=rand');

And it only displays the latest testimonial, but compared to my previous developed websites, with same php code it randomly displays posts.

I found a solution from this site


remove_all_filters('posts_orderby');

query_posts('orderby=rand');

The code above is removing all the filters before running the query.

What causes the problem are two plugins based from my experience WP Sticky and Post Types Order

Related Posts Plugin for WordPress, Blogger...
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.
  • wpjim

    Dude, thank you thank you thank for this fix. It was driving me crazy!

    • http://www.jlapitan.com jlapitan

      you are welcome!