Skip to content

Instantly share code, notes, and snippets.

@juliomenendez
Created September 5, 2011 19:25
Show Gist options
  • Save juliomenendez/1195724 to your computer and use it in GitHub Desktop.
Save juliomenendez/1195724 to your computer and use it in GitHub Desktop.
Show one post per author in WP
add_filter('posts_groupby', 'author_groupby');
function author_groupby($groupby)
{
global $wpdb;
$author_groupby = "{$wpdb->posts}.post_author";
if(preg_match("/$author_groupby/", $groupby)) {
// grouping we need is already there
return $groupby;
}
if(strlen(trim($groupby) == 0)) {
// groupby was empty, use ours
return $author_groupby;
}
return "$groupby, $author_groupby";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment