WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have 8 post types in wordpress and have the following query in functions.php file 8 times

So will it put load on mysql and decrease load times?

// random jokes 
function randJokes($rJokes){
  $RandJokesQuery = new WP_Query(array('post_type'=>'jokes','posts_per_page'=>$rJokes,'orderby'=>'rand')); ?>
  <h2 class="title">Random Jokes</h2>
    <?php while ($RandJokesQuery->have_posts()) : $RandJokesQuery->the_post(); ?>
      <li><a href="<?php the_permalink(); ?>"><?php if(function_exists('short_title')) { short_title(90); } ?></a></li>
    <?php endwhile; ?> 
share|improve this question
By a negligible amount only. – vancoder Apr 8 '13 at 17:58

Well yes but compared to what? Any query on the DB is going to add server load and thus page load so your question is not very useful without context.

The PHP code WP uses to order posts randomly is found in query.php:

case 'rand': $orderby = 'RAND()';

Which results in the output like:

wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR 
wp_posts.post_status = 'private') ORDER BY RAND() DESC LIMIT 0, 10

For example maybe it is 3ms, then obviously using 8 separate DB query's would add up to 24ms.

Is ordering by RAND slower than a default query or any other orderby parameters, as far as I can tell, no. It is faster than some query params, well..yes.

The actual query speed depends on your server, opcode caching, requests, and all sorts of "things".

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.