I’m trying to make a row layout where people can add an mp4 with ACF. So far so good, but when I try to add multiple video sections in the same post it outputs the same video in every player, even though they are different in the backend.
Does anyone know what I’m doing wrong?
Row layout:
<?php if (get_row_layout() == 'video') : ?>
<?php get_template_part('template-parts/sections/section', 'video'); ?>
<?php endif; ?>
Video section part
<div class="section section-type-video flex">
<?php
$video_mp4 = get_field('video_file'); // MP4 Field Name
$video_poster = get_field('video_poster_image'); // Poster Image Field Name
// Build the Shortcode
$attr = array(
'mp4' => $video_mp4,
'poster' => $video_poster,
'preload' => 'auto'
);
echo wp_video_shortcode($attr);
?>
</div>
Many thanks in advance!
3
Answers
To answer my own question, I was targetting the wrong fields. Needed to target sub_fields instead of get_field.
In ACF I set the return value of my subfield to array instead of url, to finish it I passed the url variable in the video shortcode array as an attribute.
Correct code below:
please check the ACF Documentation for get_row_layout() how to display it
Click here! to see it
now i have made a Flexible Content field called "video-section"
and created a layout called "video-main’ which contains a URL field called
"video-url"
I used this code to echo all different URLs that included in the post that I was created for testing try it if that what you want to do