Skip Navigation

[Resolved] Automatic Count

This support ticket is created 7 years 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 1 reply, has 2 voices.

Last updated by Christian Cox 7 years ago.

Assisted by: Christian Cox.

Author
Posts
#595994

Hello,
I have created three Post Types (named: Area, Sector and Routes), one the child of the other, related One-To-Many

On the display of "Area" and "Sector" I would like to display the total number of Routes available.

Is there a way to create a Loop to show it?

Thanks so much

Ivan

#596081

There's a way to create a nested View to show the Routes in an Area or the Routes in a Sector. I can show you how to display the number of Routes in a Sector fairly easily. Unfortunately there is not an easy way to calculate the total number of Routes in a particular Area (number of grandchild posts). That would require additional custom code.

To show the Routes in a Sector:
- Create a View of Routes
- Add a query filter to filter by post relationship, where post is a child of post with ID set by the shortcode attribute "wpvprchildof"
- In the Loop Output area you can use the shortcode [wpv-found-count] to display the number of results found.
- In the wpv-loop tag you can show the name of each Route using [wpv-post-title]
- Place this View on the Sector page Content Template or Template Layout. In the shortcode, add the Sector ID in your shortcode attribute like [wpv-view name='your-view-slug' wpvprchildof='[wpv-post-id id='$current_page']']. This will to pass the current Sector ID into the View so it can be used in the query filter. More about passing arguments to Views here:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/

To show the Routes in an Area:
- Create a View of Sectors
- Add a query filter to filter by post relationship
- Set the filter to show posts that are children of the current post. This will loop over all the Sectors in this Area.
- In the Loop Output area, insert the View of Routes in a Sector you created earlier, but this time instead of passing in the ID of the current page, we must pass in the ID of the current post in the loop, something like [wpv-view name='your-view-slug' wpvprchildof='[wpv-post-id]']
- Place this View of Sectors in your Area Content Template or Template Layout

Let me know if you get stuck and need additional assistance, I'll take a look.