Skip Navigation

[Resolved] View with all child posts that are part of a given relationship

This support ticket is created 6 years, 1 month 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by davidS-53 6 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#1149823

I have three post types: Safety Checks, Maintenance Tasks and Log Items.

I have relationships set up:
Safety Check has many log items.
Maintenance Task has many log items.

A log item will belong to either a check or a task- not one of each.

I need a view that shows all log items that are attached to any maintenance task- not one specific one. How would I achieve that? I've been playing with the Views filters and can't seem to work out an easy way.

Cheers!

#1150000

Hi, one way to accomplish this is with nested Views.
- Create a View of Log Items and add a Post Relationship Query Filter. Choose the Task > Log items post relationship for the filter, and set it up so that the parent Task is the current post in the Loop.
- Use the Loop Wizard to create an unordered list. In the Loop Editor, insert the post title for now.
- Create a View of Tasks with no query filters.
- Skip the Loop Wizard in the Loop Editor. Insert your View of Log items in the wpv-loop tags.
- Place the View of Maintenance Tasks on a custom Page or post template.

This approach is the easiest to set up, but it has some disadvantages. For example, you cannot add custom search filters easily, and pagination can be inconsistent because you're paginating the list of Tasks, not the lists of log items. If you need robust pagination and filters, the solution is more complicated and involves using our APIs and some custom code.
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

#1151775

Hi Christian,

Thanks for getting back to me. I need the returned log items to be in chronological order, so I doubt nested views would achieve that.

I've been through the suggested docs and still can't work out what attribites to pass to the view to only show log items in the Maintenance Task => Log Item relationship. Any suggestions- or direction to more detailed documentation?

I assume I need to start with something like this, right?

add_filter('wpv_filter_query', 'maintenance_history_view', 10, 2);
function maintenance_history_view ($attributes, $view_settings){
      
    if($view_settings['view_id'] == 1731){
        $attributes[] = array(
            
        );
          
    }
    return $attributes;

}

Cheers.

#1152216
2018-11-24 13_11_33-Edit View ‹ Flux — WordPress.png

Came up with a super easy conditional to achieve this- I should have thought of it in the first place:

[wpv-conditional if="( [wpv-post-id item='@maintenance-task-log-item.parent'] ne '' )"]
<tr>
[wpv-post-body view_template="Loop item in Maintenance History"]
</tr>
[/wpv-conditional]
#1152221

My issue is resolved now. Thank you!