Skip Navigation

[Resolved] Show second relationship info

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

Problem: I have 3 custom post types. A is related with B, and A is related with C. I have a view with C information and i want to show also B info that are related to A.

Solution: Depending on the types of post relationships, you may also need a View of post type A.
- If A-C is a one-to-many (O2M) relationship and "A" is the parent, you do not need a View of A in this case.
- If A-C is a O2M relationship and "A" is the child, there can be multiple A's related to each C, so you need a View of A.
- If A-C is a M2M relationship, there can be multiple A's related to each C, so you need a View of A, regardless of which is the parent and which is the child.

Relevant Documentation:
https://toolset.com/course-lesson/displaying-related-posts/
https://toolset.com/course-lesson/what-are-post-relationships-and-how-they-work/
https://toolset.com/course-lesson/many-to-many-post-relationships/

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

This topic contains 3 replies, has 2 voices.

Last updated by patrizioT 2 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#2122191

Tell us what you are trying to do?

I have 3 custom post types. A is related with B, and A is related with C. I have a view with C information and i want to show also B info that are related to A.

#2122359

What i have done for now:

On the view of C i have this in the loop:

<td> [wpv-post-link item='@radio-milite.child' wpvrelatedto="ids='[wpv-post-id]'"]</td>
<td>[wpv-view name="postazione-in-scheda-piano-radio"]</td>

In the view of B ("postazione-in-scheda-piano-radio" i have filter by relationship A-B with set "The post with ID set by the shortcode attribute = wpvrelatedto" and filter also by post-id with set filter "Posts with IDs set by the View shortcode attribute: ids"

It will show me all result and not filtered by loop.

#2122533

Hello, I noticed a few things in your code here:

<td> [wpv-post-link item='@radio-milite.child' wpvrelatedto="ids='[wpv-post-id]'"]</td>
<td>[wpv-view name="postazione-in-scheda-piano-radio"]</td>

1. The syntax looks unusual, because the attributes wpvrelatedto and ids do not apply to wpv-post-link shortcodes. These two attributes often apply to wpv-view shortcodes, so I'm not sure if this was a cut-and-paste error, or if something is missing from the code here? If you want to display the link to post type C, the first shortcode should be:

[wpv-post-link]

It does not need any shortcode attributes, since the shortcode is displayed in a View of C.

2. I have 3 custom post types. A is related with B, and A is related with C. I have a view with C information and i want to show also B info that are related to A.
You might also need a View of post type A, depending on the type of post relationship between A and C. All post relationships, even many-to-many (M2M) relationships, have parent and child, but they may not be obvious. If you are not sure, go to Toolset > Relationships and edit each relationship. Check the checkbox "I understand that changes to these settings may delete post associations in this Relationship" and click "Edit Settings". You can find out which is parent and which is child.

- If A-C is a one-to-many (O2M) relationship and "A" is the parent, you do not need a View of A in this case. Update the shortcode for View of B like so:

[wpv-view name="postazione-in-scheda-piano-radio" wpvrelatedto="[wpv-post-id item='@relationship-slug.parent']"]

Replace relationship-slug with the slug of the A-C post relationship. This syntax will provide the ID of the related post type A to the Query Filter for the A-B relationship. Remove the Query Filter by post ID from View of B, it is not necessary. Only the post relationship filter is necessary. That should be all you need to do if A-C is a O2M relationship and "A" is the parent.

- If A-C is a O2M relationship and "A" is the child, there can be multiple A's related to each C, so you need a View of A.
- If A-C is a M2M relationship, there can be multiple A's related to each C, so you need a View of A, regardless of which is the parent and which is the child.
- Create a View of post type A
- Add a Post Relationship Query Filter for the A-C post relationship, set by "The current post in the loop".
- In the Loop, insert the post title shortcode for testing purposes only, followed by the View of B with no shortcode attributes:

related post type A: [wpv-post-title]<br />
[wpv-view name="view-of-b"]

- Edit the post relationship Query Filter in the View of B. Set it to "the current post in the loop".
- In View of C, replace the shortcode for View of B with the shortcode for View of A. No shortcode attributes are necessary.
- You should see a list of post type A related to each C, and nested under each A you should see a list of related B's:
Post C 1
- Post A 1
--- Post B 1
--- Post B 2
- Post A 2
--- Post B 3
--- Post B 4
- Post A 3
Post C 2
- Post A 3
--- Post B 6
--- Post B 7
--- Post B 8
--- Post B 9

... and so on. You can verify the A's are related to each C as expected. If not, the Query Filter in View of A needs adjustment. Once all the relationships A, B and C are verified, you can delete the post title shortcode from View of A. Then you will see only a list of B's related to each C.

Let me know if you have questions about these modifications, and I can offer more direct guidance.

#2126277

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.