[Gelöst] Query a sub-relationship but get a single unified and ordered list
This support ticket is created vor 2 Jahre, 11 Monate. 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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
I would like to be able to traverse a set of relationships so that I can display a list of Training in my Posts in an ordered way.
Posts -> Audience -> Courses -> Trainings
It is not useful to do a nested query as the Training must be ordered by delivery date so that the viewer can see upcoming training classes that relate to this post, and that it worked going forward into the future without having to associate all future trainings with more and more posts.
Hello and thank you for contacting the Toolset support.
You can build this using a few nested views, and some cleanup code. The views will return the IDs of the posts separated by comma. Then you can pass this view as a shortcode argument.
Check the custom code for cleaning up the view's markup. https://toolset.com/forums/topic/need-to-strip-views-formatting/
Note that you will need to use the legacy views to build this.
If you want to use the Blocks editor for the view, then you will need to hook into the view's query filter and programatically change the WP_Query arguments, especially 'post__in':
add_filter( 'wpv_filter_query', 'wpv_filter_query_callback', 10, 3 );
function wpv_filter_query_callback( $query_args, $view_settings, $view_id ) {
global $post;
if ( $view_id == 1234 ) {
//1. get the audiences related to the current post $post->ID
//2. get the courses from the audiances
//3. get the trainings from the courses
//4. $query_args['post__in'] = $trainings;
}
return $query_args;
}