我用下面的函数为每个作者显示一篇文章,效果很好,但是否可以按自定义字段排序?
<?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";
}
我尝试了以下代码,但不起作用:
...
$author_groupby = "{$wpdb->posts}.post_author
AND pm.meta_key = \'KEY\'
ORDER BY pm.meta_value DESC Limit 0,1";
...
谢谢