In the earlier ticket, the support agent had helped me set up Views for displaying table of contents.
However, I am finding it a time-consuming process to replicate it on another site and instead, thinking of writing a small plugin or function that would display the table of contents.
Course <== Main Post
----- Chapter <== Child Post
---------- Lesson <= Grandchild Post
So far, this is what I have managed but unsure about the best coding practises:
<?php
function get_course_id(){
global $post;
$type = isset($post->post_type) ? $post->post_type : null;
$id = 0;
if ( !in_array( $type, array( 'course', 'chapter', 'lesson' ) ) ) return $id;
switch ($type) {
case 'course':
$id = $post->ID;
break;
case 'chapter':
$id = toolset_get_related_post( $post->ID, 'course-chapter');
break;
case 'lesson':
$chapter_id = toolset_get_related_post( $post->ID, 'chapter-lesson');
$id = toolset_get_related_post( $chapter_id, 'course-chapter');
break;
}
}