从最近3个帖子中随机选择一个 时间:2014-02-20 作者:Ered 好的,我有这个: $args=array( \'orderby\' => \'rand\', \'order\' => \'DESC\', \'posts_per_page\' => 1, \'offset\' => $offset, ); $q = new WP_Query($args); if ($q->have_posts()) {} 我要找的是随机显示最后3篇帖子中的一篇:SELECT * FROM (SELECT * FROM `wp_posts` WHERE `post_type` = \'post\' ORDER BY post_date DESC LIMIT 3) AS temptable ORDER BY RAND() LIMIT 1 1 个回复 SO网友:Jesse $args=array( \'orderby\' => \'rand\', \'order\' => \'DESC\', \'posts_per_page\' => 3, \'offset\' => $offset, ); $q = new WP_Query($args); if($q->post_count>0){ $random_post = $q->posts[mt_rand(0,2)]; } 另外,请注意,ORDER BY RAND()对性能非常不利 结束 文章导航