Your data model is interesting. You can answer this question better than me, but I don’t know if we really can say, as @toscho does, that a lesson will never be shared between courses, or that no two levels will have the same lesson in.
I believe that a lesson and a course are both post-like things, but a level is something that makes less sense on its own and needs context (ie its lessons) to be meaningful.
If I was building this, I would relegate ‘level’ to a taxonomy of lessons, and I would use using Posts 2 Posts to relate lessons to courses. Then to get a lesson I would query it directly. For a level in a course I would query lessons in that level’s term that were also related to the course.
For the following reasons:
-
Templating You get the benefits of
single-lesson.php
etc in your template hierarchy. If you do it @toscho’s way, if you wanted different templates for lessons, courses etc you would need to do something slightly complex, like introduce a conditional before the template was rendered, and handle it yourself. -
Readability A query for
post_type=lesson&level=level_one
is more readable thanpost_parent=123243
(or whatever). -
Flexibility Want a lesson shared between two courses? Want to reuse lessons across levels? You can do it. With straight post hierarchy, you’d need to duplicate material in the database, which is a recipe for trouble.
-
Simplicity of Levels I admit that this is the point where the system is less flexible, but I think that is ok – it might not be, for your use-case! If you want to have the same name for levels (eg Level 1, Level 2, Level 3) across all your courses, why not have them in the same place? If you need to have per-course, per-level descriptions, add a postmeta field to your course with the description in it. Less flexible, but perhaps enough.