', $after = '', $show_pass_post = false, $duration='') { global $wpdb; $mdv_most_commented = wp_cache_get('mdv_most_commented'); if ($mdv_most_commented === false) { $request = "SELECT ID, post_title, comment_count FROM $wpdb->posts"; $request .= " WHERE post_status = 'publish'"; if (!$show_pass_post) $request .= " AND post_password =''"; if ($duration !="") $request .= " AND DATE_SUB(CURDATE(),INTERVAL ".$duration." DAY) < post_date "; $request .= " ORDER BY comment_count DESC LIMIT $no_posts"; $posts = $wpdb->get_results($request); if ($posts) { foreach ($posts as $post) { $post_title = htmlspecialchars($post->post_title); $comment_count = $post->comment_count; $permalink = get_permalink($post->ID); $mdv_most_commented .= $before . '' . $post_title . ' (' . $comment_count.')' . $after; } } else { $mdv_most_commented .= $before . "None found" . $after; } wp_cache_set('mdv_most_commented', $mdv_most_commented); } echo $mdv_most_commented; } ?>