Skip Navigation

[Resolved] Related posts of child post – listed on child post

This support ticket is created 5 years, 4 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 1 reply, has 2 voices.

Last updated by Luo Yang 5 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#1282431
3.jpg
2.jpg
1.jpg

Ok - this is a solution I found to a problem after searching far and wide.
- this is more for help to others and to see if this is the 'correct' way to do this.

My issue was with Parent Child relationships and displaying related child posts on the child post itself.

I have this relationship:

Parent: Job Categories
Child: Job Descriptions

I wanted to show related job descriptions on each individual job description that were related by parent post type

E.g
If the Parent Job Category was: Health Care & Medical
And the Children Job Descriptions of this Post Type were: Registered Nurse, Obstetrician, Operating Theatre Technician.

On the \job-descriptions\registered-nurse post type, there is a view that displays any other posts that are related - in this case it would be: Obstetrician, Operating Theatre Technician

I tried this: https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/displaying-related-child-posts/
But couldnt get it to work.

So I found a solution like this.

Create a View that list the child post type and the fields - in this case "Job Descriptions"
(image 1)
Then select a Filter that works on the relationship - then select "The post with ID set by the shortcode attribute".
(image 2)

Now when you insert the view in to a related Child page, in this case a template that is applied to all of the Job Descriptions custom post type you need to add the shortcode parameter that calls the parent post type, like this:

[wpv-view name="related-job-descriptions" wpvrelatedto='[wpv-post-id id='@job-category-job-description.parent']']

Where "@job-category-job-description.parent" <- is the relationship that you defined.
(image 3)

Bonus:
If you want to reuse this view in the parent post type, you have to adjust the shortcode like this:

[wpv-view name="related-job-descriptions" wpvrelatedto='[wpv-post-id id="$job-category"]']

I hope this helps someone else stuck in a pickle.

Id also like a verification if this is an ok way of displaying related pages, as the documentation above didnt work for me.

Cheers

#1282697

Hello,

Thanks for sharing the solutions, it will help other users, and I think your workaround is OK.

section "Using Views only"

But as you mentioned above:
the documentation above didnt work for me.

This is abnormal, please make sure you have followed our document to setup the content template and post view:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/displaying-related-child-posts/

One things need to be pay attention:
in step (2): Creating a Content Template for the parent post
Make sure you have added the item=”@slug-of-the-relationship.parent” argument to its shortcode, for example:
[wpv-post-body view_template="my-ct" item="@slug-of-the-relationship.parent"]

Please let me know if you need more assistance for it.