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!
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/
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.
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]
My issue is resolved now. Thank you!