Post loop inside current post – is this approach valid for avoiding pitfalls?


I have a post type called lesson that contains various topics.

A topic has its own route and when a topic template is loaded it sets the post to be the given topic post.

The thing is, I want to display each topic on the lesson template page. That means after I am done displaying topics I need the state reset back to lesson so that I can resume after displaying the topics and have the lesson data again.

I am doing this as

global $post;
$les_post = $post;
$lesson = array('post'  => $post)

<div class="ld-lesson-topic-list">
plugin_get_template_part( 'lesson/listing.php', array(
                    'course_id' => $course_id,
                    'lesson'    => $lesson,
                    'topics'    => $topics,
                    'quizzes'   => $quizzes,
                    'user_id'   => $user_id)); 

// get back to lesson post
$post=$les_post ;?>

Seems to work, but I can’t help but think this could lead to unforseen issues. Is there better way?


, Brian 2 years 2019-10-27T04:51:19-05:00 0 Answers 85 views 0

Leave an answer