diff --git a/classes/smartmenu_item.php b/classes/smartmenu_item.php index 62833ffdf9a..875ce2847ed 100644 --- a/classes/smartmenu_item.php +++ b/classes/smartmenu_item.php @@ -641,6 +641,9 @@ protected function generate_dynamic_item() { $sql = " SELECT $select FROM {course} c $join"; $sql .= $where ? " WHERE $where " : ''; + // Sort the courses in ascending order by its display field. + $sql .= ($this->item->displayfield == self::FIELD_SHORTNAME) ? " ORDER BY c.shortname ASC " : " ORDER BY c.fullname ASC "; + // Fetch the course records based on the sql. $records = $DB->get_records_sql($sql, $params);