Skip Navigation

[Resolved] displaying child posts when parent post in a view is clicked

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

Assisted by: Luo Yang.

Author
Posts
#1125314

I have a Post Type called, eg. Food (parent to Types of Food)

I then have another post type called Types of Food (children to Food)

There share the same taxonomy. Lets call it category.

I use a view to display the Food post type in a list.

I want to have the ability to click a Food item in the list.
On click this should then show all the child posts (Types of Food) as a list where the category term is the same.

I want to have the ability to click a Types of Food item in the list.
On click, this should display the body content of the Types of Food item I have clicked.

This should all be on the same page. Three columns type of thing.
Click list item in column 1 = list of items appears in column 2
Click list item in column 2 = body content appears in column 3

Post type: Food(PT) --------Types of Food(PT) ------ Body content (of Types of Food PT)
Relationship: parent------------child-----------------content of child
Display: list ----------------------list-------------------one at a time text

I need to prevent multiple http requests when a users is clicking about, I would presume some JS would be used to make this happen.

#1125866

Hello,

I suggest you setup a nested view, for example:
1) Parent post view, query "Food" posts, in the view's loop, display below child view

2) Child post view, query "Types of Food" posts, filter by the post type relationship:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-many-related-items
In view's loop, display the post content
hidden link

3) For the click function, please try to setup some custom JS codes, for example, jquery toggle:
hidden link

To setup the custom JS codes, please check our document:
https://toolset.com/documentation/user-guides/adding-custom-javascript-views/