Quick random WordPress post hack
Posted: December 26th, 2009 | Author: shesek | Filed under: Wordpress | Tags: Wordpress hacks | No Comments »A friend of mine, Dima, was looking for a plugin that’ll make it possible to link to random post for his new site, shlat.im.
He told me over IRC that he couldn’t find any simple plugin to do it, and I replied with this quick hack:
get_var('SELECT ID FROM '.$wpdb->posts.' WHERE post_type=\'post\' AND post_status=\'publish\' ORDER BY RAND() LIMIT 1'));
Just stick it in a rand.php file in the wordpress folder, and link to it. it doesn’t get any simpler than that.