We use relationships to connect two post types. On single pages this works well by displaying content related to the current post. However, if we want to use this in loops, it's not working. We would like to have something like this:
Loop of all teachers
> Each teacher is shown with name (= post title) and the classes they teach (= post title of the related posts)
As I said, for the single pages this works by using a content template. But as soon as we try to implement this with a view, we don't get any results. If we hardcode the post ID and add it as a shortcode parameter, it works. But for a loop this is not possible to implement.
We would like to use the name & related classes in a Avada loop or Revolution Slider element, we don't use the native Toolset blocks.
Can you tell me how I'd set up the structure of content template and view(s) so I can have them in our loops?
So, we are talking about a teacher, and displaying their linked classes via a View.
In the context of a single teacher, displayed via a Content Template, we would add a View to that template to loop over the connected classes. The View would need a Query Filter to specify that we wanted to show classes connected to the current teacher (which would be the page where this View is shown).
If you wanted a View of teachers, and for each of the teachers looped over it would similarly output the linked classes, you would need essentially the same set up, with a View to list the classes and a Query Filter to specify which teacher's classes to list, but in this case rather than "the page where this View is shown", the current teacher would be the current post in the loop (reflecting the context of the loop of the outer View displaying teachers).
If your Query Filter in that case is set to "the page where this View is shown", then that page is the page where the View is added, not a teacher post, hence I wouldn't expect any results.