Using get_posts() instead of using $wpdb
Removed unused code