Skip Navigation

[Resolved] Great-GrandParent(Child) View

This support ticket is created 6 years, 6 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)

Author
Posts
#911406

I have 4 CPTs.
State
City
Branch
Company

I set 3 relationships.
State and City is one to many. State(one)-City(many)
City and Branch is one to many. City(one)-Branch(many)
Company and Branch is one to many. Company(one)-Branch(many)

I set data for each CPT.
State: Nevada,Oregon,North Carolina
City: Reno,Tillamook,Dunn,Fayetteville
Branch:Apple Reno Branch,Google Tillamook Branch,Google Dunn Branch,Microsoft Fayetteville Branch,Google Fayetteville Branch
Company:Apple, Google, Microsoft

My goal is displaying Company names in a each State page.
For example, in the North Carolina page,


<h1>North Carolina</h1>
In this State, these companies have a branch.

<ul>
<li>Google</li>
<li>Microsoft</li>
</ul>


I can display Company names in a each City page, by following this instructions.
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/displaying-fields-of-grandparents/

Please see my site's directory:
/city/reno/
/city/fayetteville/

But it is very hard for me to display Company names in a each State page.
Would you give me any advice?

#911420

Company, to the State posts, is a parent of a Grand Child (Branch)
So it's basically on the same level as City.

Hence, to display Companies on State posts, you display Companies that are parent to the Branch which is child to the City which is child to the state.

So, you will set up a View that Queries the child (Branch) and set a Query Filter that says:
Select posts in Any relationship that are a related to the current post in the loop.
To the Loop of this View you insert what you want to display of the parent post Company by using the ID attribute of the Toolset ShortCodes, when you insert them, you can define to display the data from the related parent.

Now, we have a list of Companies that are parent to the Branch which is child to "the current post in the loop".
This means, we create another View, and query the Post type City, and add a Query filter again like:
Select posts in Any relationship that are a related to the current post in the loop.

In this View's Loop you insert the First View.

This Second View, you insert to the Post (single post) of Type State.

This should now query Cities, that belong to the current state, and then, Branch that belong to that city, and then finally it outputs the Company set as parent to those branches.

#911869

Thanks Beda,

I set the view, but a problem occured.

Please see:
MyURL/Great-GrandParent/state/north-carolina/

North Carolina has Google Dunn Branch and Google Fayetteville Branch, so "Google" appears twice.

Is my setting wrong? Or how to avoid this?

#911981

Hi, in the setup Beda described there is no way to avoid the duplicate Google results. There is one way to get around this, but the approach has a few restrictions. In the View of Company names:
- Pagination, specially AJAX pagination, will not work.
- Parametric search, specially AJAXed parametric search, will not work.
- Other future features are not guaranteed to work.

If these risks are acceptable, I can give you some more information about how this can be set up. Let me know.

#912121

Hi Christian,

I'll take another approrch. Thank you for your help!