Skip to content

Instantly share code, notes, and snippets.

@dangtrinhnt
Created August 1, 2016 08:52
Show Gist options
  • Save dangtrinhnt/02b0f89611bd794ed8b0ea7109ae7b7a to your computer and use it in GitHub Desktop.
Save dangtrinhnt/02b0f89611bd794ed8b0ea7109ae7b7a to your computer and use it in GitHub Desktop.
Get Moodle courses by category ID
#! /usr/bin/php
<?php
define('CLI_SCRIPT', true);
/*
Author: Trinh Nguyen
Last update: August 1st, 2016
NOTES:
* Place this file inside a folder inside moodle root. E.g.g: /var/www/moodle/your-script/moodle_course_utils.php
*/
require_once("../config.php");
require_once($CFG->dirroot. '/course/lib.php');
require_once($CFG->libdir. '/coursecatlib.php');
$catid = 13; // Category id
$cat = coursecat::get($catid);
$children_courses = $cat->get_courses();
foreach($children_courses as $course) {
echo "### Course: " . $course->id . "\n";
}
exit(0);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment