我想只显示每位作者的最新帖子,并发现此代码可以正常工作。但是,加载页面需要很长时间,因为我在数据库中有超过100K的作者和100K的帖子。如何优化此代码?
<?php
//Displaying latest post per author on front page
function filter_where($where = '') {
global $wpdb;
$where .= " AND wp_posts.id = (select id from {$wpdb->prefix}posts p2 where p2.post_status = 'publish' and p2.post_author = {$wpdb->prefix}posts.post_author order by p2.post_date desc limit 0,1)";
return $where;
}
add_filter('posts_where', 'filter_where');
query_posts($query_string);
//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
...
?>
以下是该代码的原创文章。
http://www.dbuggr.com/smallwei/show-latest-post-author-wordpress-front-page/