I want to show only one latest post by each author and found this code that it working. However, it takes too long to load the page since I have over 100K authors and 100K posts in database. How can I optimize this code?
<?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();
...
?>
Here is an original article for the code.
http://www.dbuggr.com/smallwei/show-latest-post-author-wordpress-front-page/