I had no idea wp-stats had most emailed in it! Awesome job, Lester.
I broke out the most emailed code into a separate plugin
<?php
/*
Plugin Name: Get Most Emailed
Plugin URI: https://www.lesterchan.net/
Description: Get most emailed post using Lester Chan's wp-email plugin.
Author: Lester Chan
Version: 1.0
Author URI: https://www.lesterchan.net/
*/
### Function: Get Most Emailed Post
function get_mostemailed($limit = 5) {
global $wpdb, $post;
if(function_exists('wp_email')) {
$mostemailed= $wpdb->get_results("SELECT $wpdb->posts.ID, post_title, post_name, post_date, COUNT($wpdb-
>email.email_postid) AS 'email_total' FROM $wpdb->email LEFT JOIN $wpdb->posts ON $wpdb->email.email_postid = $wpdb->posts.ID
WHERE post_date < '".current_time('mysql')."' AND (post_status = 'publish' OR post_status = 'static') AND post_password = ''
GROUP BY $wpdb->email.email_postid ORDER BY email_total DESC LIMIT $limit");
if($mostemailed) {
foreach ($mostemailed as $post) {
$post_title = htmlspecialchars(stripslashes($post->post_title));
$email_total = intval($post->email_total);
echo "
- $post_title ($email_total) "."
";
}
} else {
echo '
- '.__('N/A').'
';
}
}
} ; ?>
Call it in the sidebar using
<?php get_mostemailed(); ?>