Paste the following code where you want to display most viewed posts
[sourcecode]
$querydetails = "
SELECT wposts.*
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
WHERE wposts.ID = wpostmeta.post_id
AND wpostmeta.meta_key = ‘post_views_count’
AND wposts.post_status = ‘publish’
AND wposts.post_type = ‘post’
ORDER BY CAST(wpostmeta.meta_value AS DECIMAL) DESC LIMIT 5
“;
$pageposts = $wpdb->get_results($querydetails, OBJECT)
?>
