Skip Navigation

[Resolved] Two multi-referente levels inside a template

This thread is resolved. Here is a description of the problem and solution.

Problem: I have two One-to-Many (O2M) relationships set up in a chained hierarchical structure, like Grandparent (Município) > Parent (Escola) > Child (Endereço). In the Município Content Template, I would like to display a list of all related Escola posts. Nested inside each Escola post, I would like to show all the related Endereço posts, for the following result.

Município 1 Template:
Escola 1
-- Endereço 1
-- Endereço 2
-- Endereço 3

Escola 2
-- Endereço 4

Escola 3
-- Endereço 5
-- Endereço 6
-- Endereço 7

...and so on.

Solution: Use two nested Views to display the related Escola and Endereço posts. You must activate the legacy Views editor to create the Endereço View, because it is not currently possible to design a nested View in the Block Editor.

This support ticket is created 4 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by raulR-4 4 years, 5 months ago.

Assisted by: Christian Cox.

Author
Posts
#1999855
Captura de Tela 2021-03-24 às 16.41.25.png
2.png
1.png

Hi.

I need create a template with the same hierarchy drawn in the black image in attachment, with two multi-reference levels. It`s possible?

Thank you.

#1999891

Hello, it looks like you have two one-to-many (O2M) relationships in a hierarchy like Municipios > Escolas > Enderecos. On the Municipio post template you want to display the related Escolas and their Enderecos posts in a nested list. This is possible in nested Views, but unfortunately it is not possible to create nested Views in a template using the Block Editor. You must enable the legacy Views editor to accomplish this, since nested Views are not supported yet in the Block Editor. Here is the general process:
1. Activate the legacy Views editor experience to create the nested View. Go to Toolset > Settings > General tab, and choose the "Editing Experience" option that enables both the Blocks editor and the legacy editor.
2. Edit the Municipios template. At the top of the screen, find the "View with: " menu. Select one Municipios post that has some related Escolas with related Enderecos posts. If you have not already created some related Escola and Enderecos content, you should create those posts first and add the required post relationships to link the Enderecos to the Escola, and relate the Escola to the Municipio. Then refresh the Municipios template editor and select the Municipios post at the top of the screen.
3. In the Municipios template editor, create a new View block to display all the related Escolas of the current Municipios post. Choose a simple loop style like unordered list. In the View loop block, insert a Single Field block to display the post title or post title with link. You should now see a list of all the Escolas related to the Municipios post you selected to "View with:". Save the template.
4. Go to Toolset > Views and create a new View. In the first popup, select "display all results" and give the View a title like "Enderecos related to the current Escola".
5. In the View editor, select the Enderecos post type in Content Selection. This View will display Enderecos posts.
6. Scroll down to the Query Filter area and add a new filter by post relationship / repeatable field group owner. Select the Escola - Enderecos post relationship, as related items of the current post in the loop.
7. Scroll down to the Loop Editor panel and click Loop Wizard. Choose a simple loop style like unordered list, and insert the Post Title or Post Title with Link field.
8. Save the View and note the View slug at the top of the View editor page.
9. Return to the Municipios template editor. In the View Loop block, insert a new Custom HTML block just below the Single Field block displaying the post title. In the custom HTML block, insert the View you just created with a shortcode like this:

[wpv-view name="your-enderecos-view-slug"]

Replace your-enderecos-view-slug with the slug of the Enderecos View you just created.
10. Save the template and visit the Municipios post on the front-end of the site. You should see a nested list of Escola and Enderecos posts related to the Municipio.

Once the lists are displaying the correct posts, you can go back to the View editor and use the Loop Wizard to add other content to the Enderecos lists, or you can edit he Escola View in the Municipios template to add other information to the Escolas list. Let me know if you have questions about this.

#1999917

Perfect! Thank you very much.

#1999919

..