OK…I had a major and embarrassing realization. This plugin is *supposed* to return a single, random item from a collection. In that case, it is working perfectly fine as-is.
So, to return an entire list of randomized items as we needed, I had to rewrite the code to work for our case.
For reference, here’s what I changed to make it work in our case:
The result set in get_randomize returns only a single row because $wpdb->get_row() and ‘LIMIT 1’ only returns a single row by design. I removed the ‘LIMIT 1’ from the SELECT statement and changed the $wpdb->get_row() to $wpdb->get_results() and enumerated the resulting array to create a single string of a randomized list.
function get_randomize($category='', $random=false) {
global $wpdb;
$table_name = $wpdb->prefix . 'randomize';
$sql = 'SELECT randomize_id, text FROM '. $table_name." WHERE visible='yes' ";
$sql .= ($category!='') ? " AND category = '$category'" : '' ;
if($random)
//Remove the LIMIT 1 from the SELECT statement to return an entire list
//$sql .= ' ORDER BY RAND() LIMIT 1 ';
$sql .= ' ORDER BY RAND() ';
else
//s$sql .= ' ORDER BY timestamp, randomize_id LIMIT 1 ';
$sql .= ' ORDER BY timestamp, randomize_id ';
//Remove this action, since it returns only a single row.
//$row = $wpdb->get_row($sql);
//New stuff to enable returning an entire list separated with <br /> tags
$strResult = "";
$arrResult = $wpdb->get_results($sql);
foreach ($arrResult as $row) {
$strResult .= $row->text . '<br />';
// update the timestamp of the row we just selected (used by rotator, not by random)
if(!$random AND intval($row->randomize_id)) {
$sql = 'UPDATE '.$table_name.' SET timestamp = Now() WHERE randomize_id = '.intval($row->randomize_id);
$wpdb->query($sql);
}
}
// now we can safely render shortcodes without self recursion (unless there is only one item containing [randomize] shortcode - don't do that, it's just silly!)
$snippet = do_shortcode($strResult);
return $snippet;
}