Quantcast
Viewing all articles
Browse latest Browse all 10

WordPress random post order not working (orderby=rand)

I had a situation where my random post wasn’t working at all, it just displayed the last added post or page (or custom post type).
I was running a custom query like:

<?php 
   query_posts('orderby=rand'); 
?>

I could be a plugin (like WP Sticky or in my case an other plugin) which is causing the problem. You can try to find and disable the plugin but a more easy solution is this:

Remove the filter before running the query:

<?php 
   remove_all_filters('posts_orderby');
   query_posts('orderby=rand'); 
?>

But watch out, the plugin which is causing the problem doesn’t adds the filter for fun, so you can wreck a plugin functionality with this solution, but it’s fast and easy Image may be NSFW.
Clik here to view.
:)


Viewing all articles
Browse latest Browse all 10

Trending Articles