Skip Navigation

[Resolved] Archive template group by parent post

This support ticket is created 5 years, 7 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 3 voices.

Last updated by felixG-2 5 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#1355199

I have the following relationship for the following CPTs:

a. State (One) to City (Many)
b. City (One) to Building (Many)
c. City (One) to Development (Many)
d. Development (One) to Building (Many)

Something like the hierarchy below:
a. State > City > Development > Building
b. State > City > Building

Note that the building have 2 parents as some building doesn't fall into a specific development/township.

How can I generate a view for Building archive as below?

City 1
- Development 1
-- Building 1
-- Building 2

Development 2
- Building 3
- Building 4

City 2
- Development 3
-- Building 1
-- Building 2

(empty container/spacer) < for building that didn't fall into specific development.
-- Building 3
-- Building 4

#1355659

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You need to use the nested views to display such content that is in other words you need to use view inside view.

You should create a view and query the City post type and add Post relationship filter from Query Filter section and format the "Loop Editor" as required.

Then, you should create another view that should query the Development post type and again add Post relationship filter from the Query Filter section and select your relationship and chose option "The current post in the loop" and format the "Loop Editor" as required. Once this view is created you should add this view to the "Loop Editor" of view that query the City post type.

You need to repeat the above step again as you have three levels of relationship City > Development > Building. So, you need one more view that should query the Building post type and add post relationship query filter and add this view to the view that query the Development post type.

More info:
=> https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/displaying-related-child-posts/#1-creating-a-view-that-lists-the-children-of-the-parent-post

#1356263

Hi Minesh,

The nested view did the trick.

One last thing, the Building have 2 parents, City and Development. Some buildings are related to both City and Development, while some are only related to City. Development are child to City. Please refer to the relationship hierarchy above.

I created the followings:
1. A view for Buildings related to the Development which work fine.
2. A view to display ALL Buildings which also include the Buildings listed in (1) above. How can I avoid duplicate Buildings by excluding the Building with Development relationship?

I had try following https://toolset.com/forums/topic/filter-a-view-by-excluding-post-who-have-a-relationship/ but couldn't figure out how to do that. I have very limited coding knowledge.

#1356717

Hello,

Minesh is on vacation, he will back in Wednesday.

In your case, you can try shortcode [wpv-conditional] to check if parent "Development" post NOT existed, then display the Buildings post information, for example:

[wpv-conditional if="( '[wpv-post-id item="@development-building.parent"]' eq '' )"][wpv-post-title][/wpv-conditional]

Please replace "development-building" with the post type relationship slug of "Development (One) to Building (Many)".

More help:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

#1357581

It works as expected.

My issue is resolved now. Thank you!