Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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>
  <ul>
    <?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; ?> 
  </ul><?php
  wp_reset_postdata();
}
share|improve this question
    
By a negligible amount only. –  vancoder Apr 8 '13 at 17:58
add comment

1 Answer 1

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:

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND 
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
add comment

Your Answer

 
discard

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.