Replaced mysql functions with the wpdb equivalent