Post loop inside current post – is this approach valid for avoiding pitfalls?
I have a post type called
lesson that contains various
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"> <?php 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 ;?> </div>
Seems to work, but I can’t help but think this could lead to unforseen issues. Is there better way?