Quotes Collection: ORDER BY RAND() fix…
A small change for the excellent Quotes Collection plugin that removes an “ORDER BY RAND()”, which tends to suck all of the randomness out of my site pretty quickly:
function quotescollection_get_randomquote($exclude = 0)
{
$offset = rand( 0, quotescollection_count() );
global $wpdb;
if($exclude && is_numeric($exclude))
$exclude_condition = 'AND quote_id <> '.$exclude;
$sql = "SELECT quote_id, quote, author, source
FROM " . $wpdb->prefix . "quotescollection QC
WHERE visible = 'yes'
".$exclude_condition."
LIMIT " . $offset . ", 1";
$random_quote = $wpdb->get_row($sql, ARRAY_A);
if ( !empty($random_quote) ) {
return $random_quote;
}
else
return 0;
}
There’s an additional query, but it doesn’t have to allocate a random number for each quote in your database. Which is nice. Hope this helps.
