public function last_episode() { global $wpdb; $next_season = $this->next_season(); if ($next_season) { $date_condition = "AND DATE(p.post_date) < '" . $next_season->start_date('Y-m-d') . "'"; } else { $date_condition = ""; } $sql = "SELECT\n\t\t\t\te.*\n\t\t\tFROM\n\t\t\t\t`" . Episode::table_name() . "` e\n\t\t\t\tJOIN `" . $wpdb->posts . "` p ON e.post_id = p.ID\n\t\t\tWHERE\n\t\t\t\tp.post_type = 'podcast' AND\n\t\t\t\tp.post_status = 'publish' \n\t\t\t\t{$date_condition}\n\t\t\tORDER BY\n\t\t\t\tp.post_date DESC\n\t\t\tLIMIT 0,1\n\t\t"; return Episode::find_one_by_sql($sql); }