This isn’t really an ACF issue, having a bunch of Embedded videos will tank any page regardless of how they’re implemented.
You should really be looking into loading them via AJAX, so when you first load the page there are NO videos loaded at all until someone clicks on an element.
Heres some pseudo code that should give a general idea of how it would work.
in template:
<?php
$args = array
(
'post_type' => 'team_members'
);
$team_member_query = new WP_Query($args);
while ($team_member_query->have_posts()): $team_member_query->the_post(); ?>
<div class="team-member-ajax-trigger" data-id="<?php echo get_the_id(); ?>"></div>
<?php endwhile; ?>
In JS:
var ajaxurl = 'http://' + window.location.host + '/wp-admin/admin-ajax.php';
$('.team-member-ajax-trigger').click(function ()
{
var id = $(this).data('id');
$.ajax
({
url: ajaxurl,
data:
{
action: 'ajax_make_team_member_video',
id: id
},
method: "POST",
error: function (data)
{
console.error("FAILURE on get Ajax Items", data);
}
}).done(function (html)
{
console.log(html);
if(html === 'no_id' || html === 'no_video')
{
//Error out or something
}
else
{
//do stuff here to make a video appear.
//html should contain your oembedded video
}
});
});
In functions.php:
add_action( 'wp_ajax_nopriv_ajax_make_team_member_video', 'ajax_make_team_member_video' );
add_action( 'wp_ajax_ajax_make_team_member_video','ajax_make_team_member_video' );
function ajax_make_team_member_video()
{
if(!isset($_POST['id']) || !$_POST['id'] || !is_numeric($_POST['id'])):
echo 'no_id';
wp_die();
endif;
$id = $_POST['id'];
$video = get_field('oembed_video',$id);
if(!$video):
echo 'no_video';
else:
echo '<div class="ajax-loaded-video">'.$video.'</div>';
endif;
wp_die(); //always end with wp_die when using ajax
}
Blah. Found it. Old version of a plugin was loading in it’s own ACF PRO. I’m a doof and never updated the version number, so it looked like it was the same plugin stack.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.