//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');
I would like to modify the code above: Is it possible change the order of the record from date by meta_value?
Example:
CHANGE
order by p2.post_date
TO
meta_key='name_key' ORDER BY meta_value
Thanks, but if I remove post_where do not Displaying latest post per author
Take a look at the WordPress Codex:
http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_orderby
If you’re making the WP_Query yourself you can change the
orderby
parameter tometa_value
Take a look here:
http://codex.wordpress.org/Class_Reference/WP_Query
I think you can do this entirely from the
pre_get_posts
action. So try removing yourposts_where
filter and replacing it with:Note: there is no conditional logic here and all posts everywhere will be sorted this way.