I just want to sort posts from a standard query based on last comment date. I tried something like this (code below) but I can't get it right. PS: 'dzialy' => $cat this is custom taxonomy named dzialy and $cat is specified id of that category.
function forum_commentsjoin($join) {
global $wp_query, $wpdb;
if ($wp_query->query_vars['post_type']=='forum' && isset($wp_query->query_vars['dzialy'])) {
$join .= "LEFT JOIN $wpdb->comments ON $wpdb->comments.comment_post_ID=$wpdb->posts.ID";
}
return $join;
}
...and later on...
$args = array( 'post_type' => 'forum', 'dzialy' => $cat, 'posts_per_page' => $ilosc, 'orderby'=>'comment_date', 'order'=>'DESC', );
print_r($loop->query);
...after that…
Array ( [post_type] => forum [dzialy] => 1468 [posts_per_page] => 20 [orderby] => comment_date [order] => DESC )