Skip Navigation

[Resolved] Showing Related Siblings

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 6 replies, has 2 voices.

Last updated by jacoP 2 years ago.

Assisted by: Nigel.

Author
Posts
#2490509

Tell us what you are trying to do?

Show related siblings of CPT 'trailhead'. A parent child relationship exists between Trail Networks and Trailheads. I want to show trailheads that are siblings of the currently displayed trailhead.

Is there any documentation that you are following?

I've reviewed available documents.

Is there a similar example that we can see?

N/A.

What is the link to your site?

dev.winelands.coom

#2490511

Further Background. A one to many relationship exists between Trail Networks and Trailheads.

#2491429

Nigel
Supporter

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

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

Hi there

It seems that we don't have documentation for how to do this with the current blocks-based UI, so let me describe what is involved.

(For reference, the documentation for the legacy interface is: https://toolset.com/documentation/legacy-features/views-plugin/displaying-brother-pages/.)

Assuming the starting point is a template to show the child posts (where you want to show other posts that are children of the same parent, i.e. siblings), you need to insert a another content template which you trick into thinking that the current context is the parent post, and to that template you add a View to display its child posts (minus the currently displayed child post).

I set this up on a sandbox site so that you could see the implementation. You can access the admin pages via this link: hidden link

I created post types Projects (parent) and Tasks (children), with some sample data.

There is a Content Template to display single Tasks.

There is another Content Template which is not assigned to any post type which contains the View to display child posts, and this Content Template gets added to the first template for tasks.

The context for the template needs to be set to the parent Project post for this to work.

It's only possible to do that by inserting the template via shortcode (there is a Content Template block that doesn't allow for switching context), so you will see that is done with a shortcode like so:

[wpv-post-body view_template="project-context" item="@project-task.parent"]

The view_template attribute is the slug of the template, while the item attribute is used to set the context to the parent post of the project-task relationship. (The Toolset Shortcodes link in the admin toolbar lets you generate such shortcodes rather than having to remember them; choose to insert a Content Template and for the Posts Selection specify the relationship as required.)

The final piece is that the View, which displays tasks, needs to only display tasks of the "current" project rather than all tasks, and so in the Content Selection settings for the View block, you need to add a post relationship Query Filter to show posts related to the current post in the Projects-Tasks relationship.

The setting not to include the current page in the results means that only sibling tasks are shown and the current task isn't repeated.

Take a look and let me know if you run into problems.

#2491869

Hi Nigel,

Thank you for the comprehensive answer. I have attempted to follow the instructions but come up with a blank result.

Here are the relevant details and steps:

1. CTP = Trail Network (Parent) and Trailhead (Child)

2. On the Trailhead single view I wish to display other related/sibling trailheads. For example, the trail network is Green and the trailheads are Alpha, Beta & Zeta. When viewing Zeta, I wish to see Alpha and Beta listed as 'related' trailheads. These are all connected to trail network Green, but there is no relationship to each other.

3. I have followed your steps to create an unassigned template (called Trailhead Siblings). To this I added a filtered view (query post filter to only show related posts).

4. I've added the shortcode ([wpv-post-body view_template="trailhead-siblings" item="@trail-network-trailhead.parent"]) to the the Single Trailheads Template below a heading 'Test Related Trailheads'.

5. No trailheads are returned despite the relationship existing and sample data being present?

What am I missing here?

#2491899

Nigel
Supporter

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

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

It sounds like you have followed the right steps, but I can't be sure without looking. Could I get access to your site to check?

Let me set a private reply to get credentials from you. You may want to create a temporary admin user that you can later delete.

And be sure to have a current backup.

#2492661

Nigel
Supporter

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

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

It was pretty much correctly set up, but I found that the generated version of the shortcode (produced via the Toolset Shortcodes link in the admin toolbar) used the template ID rather than the slug, so I changed where you inserted the shortcode to that, and now it works as intended.

hidden link

(I'm not sure why, but it's always helpful to generate the shortcodes to prevent typos etc., or anything unexpected like this.)

#2492915

Thanks for the help, Nigel!