While customizing LearnDash I came across an issue in the topic.php file where the $lesson_post variable was returning null even when there was a parent lesson for the topic.
So, after digging around at the LearnDash source code a bit I came up with this simple solution to grab the lesson whenever I needed using the topic post which is accessible via $post.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|$parent_lesson_id = learndash_get_setting( $post, 'lesson' );|
|$parent_lesson = get_post( $parent_lesson_id );|
Not sure if others will find this helpful, but there are not a ton of extensive docs or articles on developing for LearnDash so wanted to share 🙂
5 thoughts on “Get Lesson Object for a Topic in LearnDash”
Thank you, Thank you, Thank you Zac, not sure why but the documentation related to learndash_get ‘anything’ is very lean to non-existent. You changed the course of my evening, thank you 🙂 I used your code to do the following titles i needed for course and lesson by referencing the topic $post:
$parent_lesson_id = learndash_get_setting( $post, ‘lesson’ );
$parent_lesson = get_the_title( $parent_lesson_id );
$parent_course_id = learndash_get_setting( $post, ‘course’ );
$parent_course = get_the_title( $parent_course_id );
LikeLiked by 1 person
Do you have any idea how can i get the course category of the specific course?
I am putting the courses on separate categories, and I want to get the value/name of that category.
Do you have any idea?
Thanks in advance.
LikeLiked by 1 person
It’s just a meta field, so same way you would get any other meta field with WP Query
LikeLiked by 2 people
Hi! Thank You very much!
Could You tell how to get the next lesson’s link?
I can’t find any learnDash functions info :(.
I’m trying to make lesson autocompleting after completing last topic (if there’s no lesson’s quiz) and redirection to next lesson. Or, if there is a lesson’s quiz – redirect to the quiz.
I’m not sure about that. I would contact LearnDash support if you’re not able to find it. The documentation is pretty sparse.