Skip Navigation

[Resolved] Relationship in View not working

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

Problem:

Display grandchild posts with views.

Solution:

It needs nested views, for example:
https://toolset.com/forums/topic/relationship-in-view-not-working/page/2/#post-1783931

Relevant Documentation:

This support ticket is created 4 years, 2 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 17 replies, has 3 voices.

Last updated by larryL 4 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#1768083

In my camera issue view (&view_id=7445) I have a column that displays the location of the camera which is related to the title of the camera in the first column. IOW, in the issue form, the user selects a camera and that camera has a location that it is related to already.

So we are dealing with 3 CPTs (Cameras) (Camera Issues) (TMNA Locations).

The location (TMNA Location) is related to a (Camera).
A (Camera Issue) is related to a (Camera),

However, I cannot get the location of the camera to display in my view of issues. I've tried every type of post relationship for the (TMNA Location) field I can think of and it won't show up. I have to be doing this wrong. How do I get the related location to show up automatically for the selected camera for the (post) issue in the view?

Thanks!

#1768795

Hello,

How do you setup the post type relationships?

I assume we are talking about three post types:
- Cameras
- Camera Issues
- TMNA Locations

One-to-many relationship between Cameras and Camera Issues
One-to-many relationship between Camera Issues and TMNA Locations

If it is, it needs a nested view, for example:
1) Parent post view
- Query Camera Issues posts
- Filter by relationship between Cameras and Camera Issues
- In view's loop, display below child post view

2) Child post view
- Query TMNA Locations posts
- Filter by relationship between Camera Issues and TMNA Locations
- In view's loop, display TMNA Locations post information

In single Cameras post content, display the Parent post view, and test again.

#1769185

Actually all the relationships are many to many.

So how would I create this nested view?

Just generate a custom view that looks at one field 'location' and then insert it in the 'parent' view?

#1769985

Yes, you are right, in your case:
One "Camera post" can connect with multiple "Camera Issues" posts
One "Camera Issue" post can connect with multiple "TMNA Locations" posts

So you can try the same steps as I mentioned above.

More help:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-many-related-items

#1770275
view.PNG

I created the seperate view and added the embedded view to the parent one but I'm getting no result found in the list.

#1770287

I don't see anything wrong in your screenshot:
https://toolset.com/wp-content/uploads/2020/09/1770275-view_2.png

Please provide a test site with the same problem, fill your website credentials in below private message box, also point out the problem page URLs and view URLs, I need to test and debug it in a live website, thanks

#1771633

Thanks for the details, I can login your website, and have done below modifications in your website:
1) Edit the child post view "Camera Related Location"
hidden link
In section "Content Selection", enable only post type: TMNA Locations
in section "Query Filter", change the filter to:
Select posts in a Camera Issues TMNA Locations relationship that are a related to the current post in the loop.

2) Edit one "Camera Issue" post:
hidden link
in section "Camera Issues TMNA Locations", connect one existed "TMNA Location":

3) Test it in front-end:
hidden link
It works fine, can you confirm it? thanks

#1771799

Well, you are correct that it does work the way you set it up. But that isn't exactly what I had in mind.

The hierarchy of relationships is as follows: tmna location>camera>camera issues. Therefore when a camera issue is created and the user selects a camera, the location is already linked to the camera. So that location should be retrieved from the same place. IOW, we have:

The Camera Issue linked to a Camera which is linked to a tmna location(s). My goal is to eliminate the location field from the camera issue form altogether since we already know the location of the camera (as it's already linked in the database).

#1772803

I have tried the credentials you provided above:
https://toolset.com/forums/topic/relationship-in-view-not-working/#post-1771567

But get below error message:
There has been a critical error on your website. Please check your site admin email inbox for instructions.

It seems there are PHP errors in your website, please fix it first, then update here.

#1773861

Sorry luo, it was a typo in a function. It's fixed now.

#1775173

There are lots of post type relationships in your website, some of them are duplicated or useless, for example:
Camera Issues Cameras:
hidden link
Cameras Camera Issues
hidden link

Please point out the correct relationships for you mentioned above:
The hierarchy of relationships is as follows: tmna location>camera>camera issues
Which post type relationship is for "tmna location>camera"
Which one is for for "camera>camera issues"

To avoid more misunderstandings, please elaborate the questions with more details

#1776617

Which question did you have?

#1776621

Please point out the correct relationships for you mentioned above:
The hierarchy of relationships is as follows: tmna location>camera>camera issues

Here are my questions:
Which post type relationship is for "tmna location>camera" ?
Which one is for for "camera>camera issues"?

Please point out the correct relationships URLs

#1778419

Sorry, I guess I didn't understand your original question.

The hierarchy is as follows:

TMNA Location> Cameras > Camera Issues

Each Camera is mapped to a TMNA Location so (in theory) when a Camera Issue is entered an a Camera is selected the location should appear automatically because it's related to the Camera.

Camera is related to one (or more) TMNA Locations. camera-tmna-location
Camera is related to one (or more) Camera Issues. camera-camera-issue

I hope this makes sense.

#1779677

Hi,

Luo is on vacation, so I'll be following up on this ticket shortly, after understanding the full context.

Thank you for your patience.

regards,
Waqar