0

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(); } 
1
  • By a negligible amount only. Commented Apr 8, 2013 at 17:58

1 Answer 1

0

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".

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.