//Displaying latest post per author on front page
function filter_where($where = \'\') {
global $wpdb;
$where .= " AND vipwp_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\');
我想修改上面的代码:是否可以通过meta\\u值从date更改记录的顺序?
示例:更改
order by p2.post_date
至
meta_key=\'name_key\' ORDER BY meta_value
谢谢,但如果我删除post\\u,其中不显示每个作者的最新帖子
SO网友:helgatheviking
我想你完全可以从pre_get_posts
行动因此,请尝试删除posts_where
过滤器并替换为:
function wpa_69199( $query ) {
set_query_var( \'orderby\', \'meta_value\' );
set_query_var( \'meta_key\', \'name_key\' ); //field you\'d like to order by
}
add_action( \'pre_get_posts\', \'wpa_69199\' );
注意:这里没有条件逻辑,所有的帖子都将按这种方式排序。