Question

I am using LearnDash on my WordPress site, and have created the following snippet to get a list of all lessons:

function get_list_of_lessons_class(){
$args = array(
    'post_type' => 'sfwd-lessons',
    'posts_per_page' => -1,
    'post_status' => 'publish',
    );
$q = new WP_Query($args);
    if ($q->have_posts()) : 
        while ($q->have_posts()) :  $q->the_post();
        the_title();
        endwhile; 
    else:
        ;
        wp_reset_postdata();
    endif;
return $finalout;
}
add_shortcode('get_list_of_lessons', 'get_list_of_lessons_class');

Can anyone advise please how to display the course title of each lesson beside the lesson title?

Thank you.

Was it helpful?

Solution

You can get the current post's course ID from learndash_get_course_id(), e.g.

$course_id = learndash_get_course_id();
if (isset($course_id) && $course_id) echo esc_html(get_the_title($course_id));

Under the covers it's stored in a post meta value course_id, but you might as well use their helper function to read it.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top