It can be done using nested view but in your case I think using shortcode will make more sense.
And we will use the Legacy view as Legacy view will offer you more control over table design rather using blocks. To enable the legacy view, please follow the following Doc:
- https://toolset.com/course-lesson/enabling-legacy-version-of-toolset-views/
Here is the sandbox site where I tried to setup a demo and you can auto-login to it using the following link:
- versteckter Link
I've setup post types:
- versteckter Link
And custom fields as you mentioned in your previous post:
- versteckter Link
As you can see I've setup few entries for both post types with required field:
- versteckter Link
- versteckter Link
I've created the following view:
- versteckter Link
Where:
- I've called the shortcode added to "Custom Code" section as given under:
<td align="center">[show_related_post_info relationship='related-club' type='count']</td>
-- To display related post count
<td>[show_related_post_info relationship='related-club' type='field-sum' field='game-duration']</td>
-- To display sum duration
<td>[show_related_post_info relationship='related-club' type='field-average' field='no-of-players']</td>
-- To display average player
Where:
- replace relationship shortcode attribute value with your original post reference field slug. In this case for this sandbox site its "related-club".
Added the following Code to "Custom Code" section offered by Toolset:
=> versteckter Link
add_shortcode('show_related_post_info', 'func_show_related_post_info');
function func_show_related_post_info($atts) {
global $post;
$field_sum = $field_avg = 0;
$relationship = $atts['relationship'];
$type = $atts['type'];
$field = 'wpcf-'.$atts['field'];
$child_posts = toolset_get_related_posts($post->ID,
$relationship,
'parent',999,
0,array(),
'post_id',
'child');
$total_count = count($child_posts);
if(isset($relationship) and $type=='count') {
return $total_count;
}else if(!empty($child_posts)) {
foreach($child_posts as $k=>$v):
$field_sum = $field_sum + get_post_meta($v,$field,true);
endforeach;
if(isset($relationship) and $type=='field-sum') {
return $field_sum;
}else if(isset($relationship) and $type=='field-average') {
return $field_sum/$total_count;
}
}
return 0;
}
On the following page - I've added the view as given under:
- versteckter Link
[wpv-view name="show-all-jeu-post-in-table" cached="off"]
If you can see on the the frontend for the above page here is the view result:
- versteckter Link
More info:
- https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset
- https://toolset.com/documentation/programmer-reference/adding-custom-code/how-to-create-a-custom-shortcode/