Sitede bulunan yazılardan rastgele bir tanesini sitenin herhangi bir yerinde göstermek, random, rastgele yazı butonu. Sitedeki tüm girdilerden rastgele bir tanesini seçip ona bağlantı vermek çok basit.
Mysql sorgusu şöyle;
SELECT guid FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY RAND() LIMIT 1
Php ile şöyle;
<?php
$randomPost = $wpdb->get_var("SELECT guid FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY rand() LIMIT 1");
echo '<a href="'.$randomPost.'">Random Post</a>';
?>
Php kodunu göstermek istediğiniz yere yazarsanız rastgele yazı butonunuz hazır, tabii bu bir bağlantı arzunuza göre buton haline getirmek için sitil şablonuna sitili verebilirsiniz.
wp_ tablo ön eki varsayılandır, daha fazla bilgi için ve kaynak: wpdb_Class.