posts LEFT JOIN $wpdb->postmeta ON $wpdb->posts.ID=$wpdb->postmeta.post_id WHERE meta_key='views' ORDER BY CAST(meta_value AS SIGNED) DESC LIMIT $limit";
$top_posts_results = $wpdb->get_results($top_posts_sql, ARRAY_A);
echo "
"; // Put the results into a numbered list
// Output the Top Post Results in a link, each on a new line
foreach ($top_posts_results as $myrow)
{
$meta_value = $myrow['meta_value'];
$meta_key = $myrow['meta_key'];
$title = $myrow['post_title'];
$guid = $myrow['guid'];
echo "- $title
\n\r";
}
echo "
";
$wpdb->flush();
?>