Support Forum
Support › MB Views › Problem displaying videos in group - video values don't seem to be returnedResolved
Hi.
I have a video upload field which is in a group. The field is cloneable and the videos are uploaded and stored fine. They show in the field in the form fine etc.
When I come to display the videos as part of a view I have trouble.
The form is created as follows:
<?php
add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' );
function your_prefix_register_meta_boxes( $meta_boxes ) {
$prefix = '';
$meta_boxes[] = [
'title' => esc_html__( 'Job Sitter Activity Updates', 'text-domain' ),
'id' => 'job-sitter-activity-updates',
'post_types' => ['job'],
'context' => 'normal',
'priority' => 'low',
'fields' => [
[
'id' => $prefix . 'post_title',
'type' => 'text',
'readonly' => 1,
'hidden' => [
'when' => [['post_title', '!=', '']],
'relation' => 'and',
],
],
[
'id' => $prefix . 'group_updates',
'type' => 'group',
'fields' => [
[
'id' => $prefix . 'job_update_time',
'name' => esc_html__( 'Task Completion Time', 'text-domain' ),
'type' => 'time',
],
[
'id' => $prefix . 'job_update_date',
'type' => 'date',
'name' => esc_html__( 'Task Date', 'text-domain' ),
'clone_default' => true,
],
[
'id' => $prefix . 'job_update_pet',
'type' => 'text',
'name' => esc_html__( 'Choose Pet', 'text-domain' ),
],
[
'id' => $prefix . 'job_update_task_pet',
'name' => esc_html__( 'Task', 'text-domain' ),
'type' => 'radio',
'options' => [
'Meal' => esc_html__( 'Meal', 'text-domain' ),
'Walk' => esc_html__( 'Walk', 'text-domain' ),
'Medication' => esc_html__( 'Medication', 'text-domain' ),
'Litter Tray Emptied' => esc_html__( 'Litter Tray Emptied', 'text-domain' ),
'Cage Cleaned' => esc_html__( 'Cage Cleaned', 'text-domain' ),
'Pop In Visit Completed' => esc_html__( 'Pop In Visit Completed', 'text-domain' ),
'Pet Exercised' => esc_html__( 'Pet Exercised', 'text-domain' ),
'Pet Playtime' => esc_html__( 'Pet Playtime', 'text-domain' ),
'Other' => esc_html__( 'Other', 'text-domain' ),
],
'visible' => [
'when' => [['job_update_pet', '!=', '']],
'relation' => 'and',
],
],
[
'id' => $prefix . 'job_activity_description_pet',
'type' => 'text',
'name' => esc_html__( 'Notes', 'text-domain' ),
'visible' => [
'when' => [['job_update_pet', '!=', '']],
'relation' => 'and',
],
],
[
'id' => $prefix . 'job_update_task_house',
'name' => esc_html__( 'House Tasks', 'text-domain' ),
'type' => 'radio',
'options' => [
'Bins Taken Out / Put Back' => esc_html__( 'Bins Taken Out / Put Back', 'text-domain' ),
'Plants Watered' => esc_html__( 'Plants Watered', 'text-domain' ),
'House Cleanliness Maintained' => esc_html__( 'House Cleanliness Maintained', 'text-domain' ),
'House Security Check Complete' => esc_html__( 'House Security Check Complete', 'text-domain' ),
'Other' => esc_html__( 'Other', 'text-domain' ),
],
],
[
'id' => $prefix . 'job_activity_description_house',
'type' => 'text',
'name' => esc_html__( 'Notes', 'text-domain' ),
],
],
'clone' => 1,
'default_state' => 'collapsed',
'add_button' => esc_html__( 'ADD MORE TASKS', 'text-domain' ),
'collapsible' => true,
],
[
'id' => $prefix . 'group_updates_photos',
'type' => 'group',
'fields' => [
[
'id' => $prefix . 'job_update_photo',
'type' => 'image_upload',
'name' => esc_html__( 'Photo Upload', 'text-domain' ),
'max_status' => false,
'max_file_uploads' => 1,
'desc' => esc_html__( 'Please limit to one photo per day', 'text-domain' ),
'clone' => 1,
'add_button' => esc_html__( 'ADD ANOTHER PHOTO', 'text-domain' ),
],
],
'default_state' => 'collapsed',
'collapsible' => true,
'group_title' => 'Photos',
],
[
'id' => $prefix . 'group_updates_videos',
'type' => 'group',
'fields' => [
[
'id' => $prefix . 'job_update_video',
'type' => 'video',
'name' => esc_html__( 'Video Upload', 'text-domain' ),
'desc' => esc_html__( 'Please limit to one video of up to 1 minute per day', 'text-domain' ),
'max_file_uploads' => 1,
'clone' => 1,
'add_button' => esc_html__( 'ADD ANOTHER VIDEO', 'text-domain' ),
'max_status' => 1,
],
],
'default_state' => 'collapsed',
'collapsible' => true,
'group_title' => 'Videos',
],
],
'include' => [
'relation' => 'OR',
'user_role' => ['um_sitter', 'administrator'],
],
];
return $meta_boxes;
}
The view code is like this for the part that's showing the photos and videos:
{% for clone in post.group_updates_photos.job_update_photo %}
<tr>
<td colspan="5"><img src="{% for item in clone %}{{ item.thumbnail.url }}{% endfor %}"</td>
</tr>
{% endfor %}
{% for clone in post.group_updates_videos.job_update_video %}
<tr>
<td colspan="5">TITLE: {% for item in clone %}{{ item.title }}{% endfor %}</td>
</tr>
{% endfor %}
{% for clone in post.group_updates_videos.job_update_video %}
<tr>
<td colspan="5">VIDEO: <video width="320" height="240" controls><source src="{% for item in clone %}{{ item.src }}{% endfor %}" type="video/mp4"></video></td>
</tr>
{% endfor %}
It works fine for the photos but it seems that the item.xxx values aren't being returned at all. I've tried all sorts of variations of cloning the group and the field etc but nothing seems to give me a return value.
I previously had the photos and videos outside of groups and both worked perfectly fine there but wanted the groups so I could make them collapsible (they were starting to take up a lot of page space in the form).
Hi,
There was a problem while getting the video sub-field in View. Please use it as a top-field, not inside a group to make it works, I will check this case and let you know later.
Fields:
...
[
'id' => $prefix . 'group_updates_photos',
'type' => 'group',
'fields' => [
[
'id' => $prefix . 'job_update_photo',
'type' => 'image_upload',
'name' => esc_html__( 'Photo Upload', 'text-domain' ),
'max_status' => false,
'max_file_uploads' => 1,
'desc' => esc_html__( 'Please limit to one photo per day', 'text-domain' ),
'clone' => 1,
'add_button' => esc_html__( 'ADD ANOTHER PHOTO', 'text-domain' ),
],
],
'default_state' => 'collapsed',
'collapsible' => true,
'group_title' => 'Photos',
],
[
'id' => $prefix . 'job_update_video',
'type' => 'video',
'name' => esc_html__( 'Video Upload', 'text-domain' ),
'desc' => esc_html__( 'Please limit to one video of up to 1 minute per day', 'text-domain' ),
'max_file_uploads' => 1,
'clone' => 1,
'add_button' => esc_html__( 'ADD ANOTHER VIDEO', 'text-domain' ),
'max_status' => 1,
],
...
View:
{% for clone in post.job_update_video %}
{% for item in clone %}
<tr>
<td colspan="5">VIDEO: <video width="320" height="240" controls><source src="{{ item.src }}" type="video/mp4"></video></td>
</tr>
{% endfor %}
{% endfor %}
OK. Thanks Long. I wondered if that might be the case. If there is a fix that would be great but I'll revert to the non-grouped version for now.