Skip Navigation

[Resolved] Filter view by parent field

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.

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Dat Hoang 6 years, 9 months ago.

Assigned support staff: Dat Hoang.

Author
Posts
#274705

I am trying to configure a View that lists a type filtered by a field that exists on a parent.

Course (has vendor field)
|----Training

I have a "Course" type with a "vendor" field. I also have a "Training" type which is displayed in a list by date. I want to add an additional shotcode filter to the "TrainingView" that allows me to only show "trainings" that have a specific value of "vendor".

Screenie of View: hidden link

I think I want to do

[wpv-view name="Footer-TrainingList-Upcomming" vendor="scrum-org"]

however the value for vendor is not applied to the view.

Is there some way to specify that the field comes from the parent and not the target of the view?

#274967

Yes, you can achieve that by creating 2 Views.

1. Child view named "Child view - listing training posts"
- Content selection: post_type=training
- Filter: Choose "Post Relationship - Post is a child of:" => set "Post with ID set by the shortcode attribute": child_of

2. Parent view named "Parent view - listing course posts"
- Content selection: post_type=course
- Filter: Choose filter the custom field: wpcf-vendor
- In the loop of Layout HTML/CSS/JS > Put the shortcode:

[wpv-view name="Child view - listing training posts" child_of="[wpv-post-id]"]

Then put view "Parent view - listing course posts" and suitable parameter filtering the custom field "wpcf-vendor" in your page.

Explanation:
- Parent view: Query all parent posts "course" with the filter by the custom field "wpcf-vendor". These post IDs will become the parameter of child view.
- Child view: Query all child posts "training" belongs to a specific parent post "course"