Skip Navigation

[Resolved] Sibling Post Relationships

This support ticket is created 3 years, 7 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 stewartE 3 years, 7 months ago.

Assisted by: Nigel.

Author
Posts
#1730575
2.PNG
1.PNG

Hi I was wondering if you could help. I have a CPT called Departments which is realated in a 1-2 many relationship with a CPT called Services (a Department can have many Services)

I think this should be straightforward but for some reason i am having trouble getting it to work. What I want to do is on the Service pages show a list of all the other Services that are related to the same Departemt.

Note - I am using views not blocks.

Screenshot 1 shows my setup and screenshot 2 shows what I am trying to achive.

Many thanks!

#1730795

Nigel
Supporter

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

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

Screenshot 2020-08-07 at 14.01.08.png

Good job you are using Views, it is pretty difficult to do with Blocks right now, although we should hopefully be able to improve on this in the next dev cycle.

So the starting context is a child post (a service).

You will create a View to list service posts. You need to add a Query Filter to say that it should show service posts related to some department.

Which department? That's where you are stuck, I guess.

Choose to pass the parent ID as a shortcode attribute. You can see an example from my test web site (with Projects << Tasks relationship) in the screenshot. It suggests 'wpvrelatedto' as the attribute, but you can change that if you want.

Be sure that the default option to exclude the current page from results is checked (so you don't repeat the current service).

Now insert the View via shortcode in your service template. Edit the shortcode to add the wpvrelatedto attribute, using the wpv-post-id shortcode to provide the value. If you use the Fields and Views button to insert the shortcode you can use the Post Content tab to specify that the ID you want is not that of the current post (the service), but that of the parent department, which will add an item attribute to the wpv-post-id shortcode, so that you end up with something like this (based on my relationship):

[wpv-view name="Sibling tasks" wpvrelatedto="[wpv-post-id item='@project-task.parent']"]

So the id of the parent department of the current service will be passed to the View to use in the Query Filter that sets the parent.

#1731169

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.