Skip Navigation

[Resolved] Can you create a view that looks at another view's relationships?

This support ticket is created 6 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 2 replies, has 2 voices.

Last updated by larryB-3 6 years, 5 months ago.

Assisted by: Nigel.

Author
Posts
#916069

If Jane Doe (Homeowner CPT) owns a home at 123 Any Street (Property CPT), and John Doe, another Homeowner also owns that same property with Jane; can I build a view where my query is of Homeowners, and for each row return:

Homeowner Name | Property | Other Owners
Jane Doe | 123 Any St | John Doe

Is this possible? I really need the query to focus on the Homeowner so I can export 1 homeowner per row, but I'd like to know the names of other homeowners that she has a relationship with via common relationship to a piece of property.

#916175

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Larry

Your starting point is a Homeowner. You use a View to list their Properties. You want to display any other Homeowners of a given Property.

Well, the first step is to create another View that you insert into the View that displays the Properties that works in reverse, and shows the Homeowners who are related to the current Property.

Would that it were that simple, because that will show you all of the owners of the Property, which means repeating the Homeowner we started with.

I haven't implemented this to confirm it works, but this is how I think you can do it.

The first View, which lists Properties, is "aware" of the Homeowner in question. Try inserting a field using the Fields and Views button and in the post selection tab you'll be able to choose the related Homeowner. So we can get the Homeowner's post ID that way using the wpv-post-id shortcode (with the required attributes).

We need to pass that ID to our second View which lists all of the Homeowners of that Property, which we could do by using a shortcode attribute such as "ownerid". (See https://toolset.com/documentation/user-guides/passing-arguments-to-views/.)

At the end of that documentation you can see how to access the attribute in the second View.

You could then use that in a conditional shortcode (https://toolset.com/documentation/user-guides/conditional-html-output-in-views/).

In the Loop Output section it will iterate over the Homeowners of that property, and you only want it to output the owner fields if it is not the owner passed as a shortcode attribute from the parent View.

I think that should work, but if you get stuck let me know.

#916401

Thanks! I will have to work on that solution sometime in the coming weeks. It will take some time to process. I will let you know if I run into trouble. Closing this ticket for now.