Automating Course and Lesson Creation in WordPress Using LearnDash

What are you trying to achieve?

I’ve created a scenario that creates a course using the LearnDash module and then creates lessons using the LearnDash module on a WordPress website. The course and lessons are created correctly, but I don’t see how to associate the lessons with the course.

Steps taken so far

I’ve checked, and it seems that option is not available. Is there any way to perform that association within the scenario? I’ve also tried using the WordPress API call and HTTP modules without success.

Relationship Between Courses and Lessons in LearnDash (MySQL + WordPress)
This document explains how courses and lessons are related in a WordPress installation using LearnDash, at the database (MySQL) level. It is intended for developers who need to understand how this information is stored internally.

:file_folder: Base Structure: wp_posts
Both courses and lessons are Custom Post Types registered by LearnDash:

Course: post_type = sfwd-courses
Lesson: post_type = sfwd-lessons
:brain: Main Association: wp_postmeta
LearnDash uses the wp_postmeta table to relate lessons to courses using metadata.

Example:
Course ID: 51896
Lesson ID: 51907

post_id meta_key meta_value
51907 course_id 51896
51907 ld_course_51896 51896
course_id → direct relationship
ld_course_51896 → special key LearnDash uses internally
:hammer_and_wrench: PHP Function Handling This
The official LearnDash function to associate lessons with a course is:

learndash_set_course_steps($course_id, $lessons, ‘add’);
:brick: Tables Involved

wp_posts: Stores courses and lessons as CPTs.
wp_postmeta: Stores the relationship between course and lesson (course_id, ld_course_{ID})
:prohibited: Tables Not Used by Default

post_parent
term_relationships, term_taxonomy, or termmeta
:gear: Additional Considerations

It’s necessary to add course_id and ld_course_{ID} when creating lessons.
Some themes or modules rely on these metadata entries to display content.