Based on this answered question: Ordering Wordpress posts by most recent comment
I want to sort wordpress post by recent comment and new post. I need to put this in my themes function but I always get "Page not found". Anybody can help to fix this code?
function intercept_query_clauses( $pieces ) {
global $wpdb;
$pieces['fields'] = "wp_posts.*,
coalesce(
(
select max(comment_date)
from " . $wpdb->comments ." wpc
where wpc.comment_post_id = wp_posts.id AND wpc.comment_approved = 1
),
wp_posts.post_date
) as mcomment_date
from " . $wpdb->posts . " wp_posts
where post_type = 'post'
and post_status = 'publish'";
$pieces['orderby'] = "mcomment_date desc limit 10";
return $pieces;
}
add_filter( 'posts_clauses', 'intercept_query_clauses', 20, 1 );
Any help and guide really appreciate.. Thank you.
Aucun commentaire:
Enregistrer un commentaire