{"id":578,"date":"2009-04-28T21:52:55","date_gmt":"2009-04-29T04:52:55","guid":{"rendered":"http:\/\/162.243.68.163\/blog\/?p=578"},"modified":"2009-04-28T21:54:49","modified_gmt":"2009-04-29T04:54:49","slug":"quotes-collection-order-by-rand-fix","status":"publish","type":"post","link":"https:\/\/tekhedd.com\/?p=578","title":{"rendered":"Quotes Collection: ORDER BY RAND() fix&#8230;"},"content":{"rendered":"<p>A small change for the excellent <a href=\"http:\/\/srinig.com\/wordpress\/plugins\/quotes-collection\/\">Quotes Collection<\/a> plugin that removes an &#8220;ORDER BY RAND()&#8221;, which tends to suck all of the randomness out of my site pretty quickly:<\/p>\n<pre>function quotescollection_get_randomquote($exclude = 0)\r\n{\r\n        $offset = rand( 0, quotescollection_count() );\r\n\tglobal $wpdb;\r\n\tif($exclude &amp;&amp; is_numeric($exclude))\r\n\t\t$exclude_condition = 'AND quote_id &lt;&gt; '.$exclude;\r\n\t$sql = \"SELECT quote_id, quote, author, source\r\n\t\tFROM \" . $wpdb-&gt;prefix . \"quotescollection QC\r\n\t\tWHERE visible = 'yes'\r\n\t\t\".$exclude_condition.\"\r\n\t\tLIMIT \" . $offset . \", 1\";\r\n\t$random_quote = $wpdb-&gt;get_row($sql, ARRAY_A);\r\n\tif ( !empty($random_quote) ) {\r\n\t\treturn $random_quote;\r\n\t}\r\n\telse\r\n\t\treturn 0;\r\n}<\/pre>\n<p>There&#8217;s an additional query, but it doesn&#8217;t have to allocate a random number for each quote in your database. Which is nice. Hope this helps.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A small change for the excellent Quotes Collection plugin that removes an &#8220;ORDER BY RAND()&#8221;, 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 &amp;&amp; is_numeric($exclude)) $exclude_condition = &#8216;AND quote_id &lt;&gt; &#8216;.$exclude; $sql = &#8220;SELECT quote_id, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-578","post","type-post","status-publish","format-standard","hentry","category-other"],"_links":{"self":[{"href":"https:\/\/tekhedd.com\/index.php?rest_route=\/wp\/v2\/posts\/578","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tekhedd.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tekhedd.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tekhedd.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/tekhedd.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=578"}],"version-history":[{"count":3,"href":"https:\/\/tekhedd.com\/index.php?rest_route=\/wp\/v2\/posts\/578\/revisions"}],"predecessor-version":[{"id":580,"href":"https:\/\/tekhedd.com\/index.php?rest_route=\/wp\/v2\/posts\/578\/revisions\/580"}],"wp:attachment":[{"href":"https:\/\/tekhedd.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tekhedd.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tekhedd.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}