Skip Navigation

[Resolved] Getting items from a relationship within another relationship

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.

Our next available supporter will start replying to tickets in about 0.74 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 0 replies, has 0 voices.

Last updated by rusty 3 hours, 7 minutes ago.

Assisted by: Minesh.

Author
Posts
#2780642

I have a CPTs called "Projects" and "People" in a M2M relationship so I can add people to a project.
On each Project single, I can show which People are on that Project.
On each People single page, I can show which Projects that person is on.
What I want to do is show on each People single page the other people they have worked with. In other words, a list of people attached to the Projects that this person is also attached to. So pull the people from the people-project relationship and display them on the people page.

I think I need to do this with nested views, but I can't get it to work. Best I can do is get a list of all the people, but it includes duplicates. If person A worked on project X and Y with Person B, Person A will be on Person B's page twice.

I think this is the same scenario, but the answer is vague: https://toolset.com/forums/topic/is-it-possible-to-get-the-relation-of-a-relation/

#2781579

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Can I have a single people (person) post link where you list all people but also that example on that single people (person) post link what are the other people (person) you expected to dispaly.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2782237

Minesh
Supporter

Languages: English (English )

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

Can you please check now: hidden link

I've created the following view - the following view will return the people ids of related project.
- hidden link

I've also modified the view you created and adjusted the loop output as given under:
- hidden link

[wpv-layout-start][wpv-items-found]<!-- wpv-loop-start --><wpv-loop>[wpv-item index=other][wpv-view name="get-related-people-ids-belongs-project"][wpv-item index=last],[wpv-view name="get-related-people-ids-belongs-project"]</wpv-loop><!-- wpv-loop-end -->[/wpv-items-found][wpv-no-items-found]<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>[/wpv-no-items-found][wpv-layout-end]

As you can see I've dded the view "get-related-people-ids-belongs-project" to get the related people ids belongs to project.

And with the view "people-from-projects-view" I've added the Post ID query filter to filter with shortcode attribute "relatedpeopleids":

Post ID filter
Include only posts with IDs set by the View shortcode attribute "relatedpeopleids" eg. [wpv-view name="view-name" relatedpeopleids="1"]

- hidden link

Then on your single people(person) content template:
- hidden link

I've added the view as given under:

<div class="col-12">
        <h2 class="f-34 mb-4"><span class="highlight-black">Collaborators</span></h2>
       [wpv-view name="people-from-projects-view" relatedpeopleids="[wpv-view name='people-from-projects-on-people-view']"]        
      </div>

As you can see we are passing the found related people IDs belongs to project using the view "people-from-projects-on-people-view" and pass the found people IDs to shortcode attribute "relatedpeopleids".

Can you please confirm it works as expected.

#2782335

This is brilliant! What a great solution. It works perfectly! Thank you Minesh!