Snippet displaying LearnDash parent course title with lesson title

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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x