I display one post per author with function below and works fine, but is possible order by custom field?
<?php
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";
}
I've tried with code below but do not works:
...
$author_groupby = "{$wpdb->posts}.post_author
AND pm.meta_key = 'KEY'
ORDER BY pm.meta_value DESC Limit 0,1";
...
Thanks